-
| Is it possible to create a plot that uses  I've tried a few approaches in this notebook, the closest I got was to filter after stacking, but that doesn't recompute the  Plot.plot({
  marks: [
    Plot.barY(tidy, {
      filter: (d) => d.age !== "<10" && d.age !== "10-19",
      ...Plot.stackY({
        offset: "normalize",
        x: "state",
        y: "population",
        fill: "age",
        sort: { color: null, x: "-y" }
      })
    })
  ]
})  I understand this is rather niche so the answer may be in the data transformation I performed outside of Plot (totally reasonable!) | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
| You need a custom offset function that takes as basis the maximum value from the whole series and filters out the meanies: Plot.plot({
  marks: [
    Plot.barY(tidy, {
      offset: function (facets, Y1, Y2, Z) {
        for (const series of facets) {
          for (const I of series) {
            const basis = d3.max(I, (i) => Y2[i]);
            for (const i of I)
              if (Z[i] === "<10" || Z[i] === "10-19") {
                Y1[i] = Y2[i] = NaN;
              } else {
                Y1[i] /= basis;
                Y2[i] /= basis;
              }
          }
        }
      },
      x: "state",
      y: "population",
      fill: "age",
      order: (d) => d.age === "<10" || d.age === "10-19", // you can dispense with this if you work more on the offset function :)
      sort: { color: null, x: "-y" }
    })
  ]
}) | 
Beta Was this translation helpful? Give feedback.

You need a custom offset function that takes as basis the maximum value from the whole series and filters out the meanies: