Fill domain trouble

I saw in some examples that domain can be used with “string” values.
But I cant understand where im wrong.

First plot with correct legend, but no bars. How to fix it?
But second show bars, but incorrect legend
Is domain support only digits?

The problem is the grouping. You’ve asked to reduce the group by “sum”. That works for the second case because the sum of [1] is 1. However, in the words case, the sum of ["read"] isn’t a number, and it isn’t the string “read” either.

But then that leads to the question: why are you grouping? Removing the group function entirely fixes the plot:

Plot.plot({
  x: {
    tickFormat: Math.abs
  },
  y: {
    label: null
  },
  color: {
    domain: ["read", "write"],
    range: ["#e41a1c", "#4daf4a"],
    legend: true
  },
  marks: [
    Plot.barX(storage, {
      x: (d) => (d.type === "write" ? 1 * d.iops : -1 * d.iops),
      y: "name",
      fill: (d) => d.type,
      tip: true
    }),
    Plot.ruleX([0])
  ]
})
1 Like

As seen in mythmon’s example, the explicit group transform isn’t needed because using the fill channel implicitly groups things behind the scenes! This is a type of “z” grouping, as mentioned on this page: Transforms | Observable Plot

1 Like

Much Thanks, im whole day read about group, bin and other but still can not understand how it works( Thanks again!

I tried to repeat this example with double sided horizontal bar and it contains group
ttps://observablehq.com/@observablehq/plot-diverging-stacked-bar?intent=fork