Getting values for proportion reducers in Plot

Is it possible to get the values of a channel generated by a proportion or proportion-facet reducer in a binned Observable Plot? I know how to access the groups and compute summary stats like length and sum, but I’d also like to use the proportions, e.g. for use in the title:

As an aside, it would be great if I can somehow get the channel values generated by Plot as a sanity check. I think I saw a video somewhere that shows how to do that, but I can’t remember which one it was.

Many thanks for a great platform!

Michael

it is technically feasible but far from obvious, since the scope argument is meant to be internal.

      Plot.binX(
        {
          fill: prop,
          title: {
            scope: prop === "proportion" ? "data" : prop === "proportion-facet" ? "facet" : undefined,
            reduce: (I, V, basis) => basis === undefined
              ? I.length
              : `group length: ${I.length}, sum: ${d3.sum(I, i => V[i].weight)}, ${prop}: ${I.length / basis}`
          }
        },
        { x: "weight", inset: 0.5 }
      )

Would you mind opening an issue for this?

Thank you Fil. That works for me and will be happy to open an issue.

Michael

1 Like

How do you do that, I am looking for it an cannot find the doc.

You expect me to remember stuff from a year ago? :wink:
The Plot API has changed since my post, but If you look at the last example from Bin Transform, you have access to the bins when you use title in the outputs and can then return summary data such as length and sum.

This would work. Just hover over the plot to see the data.

Plot.plot({
  marginLeft: 100,
  padding: 0,
  x: {
    round: true,
    grid: true
  },
  fy: {
    label: null,
    domain: d3.groupSort(athletes, g => d3.median(g, d => d.weight), d => d.sport)
  },
  color: {
    scheme: "YlGnBu"
  },
  facet: {
    data: athletes,
    marginLeft: 100,
    y: "sport"
  },
  marks: [
    Plot.barX(athletes, Plot.binX({fill: "proportion-facet", title: bin => `length ${bin.length} sum ${d3.sum(bin, d => d.weight)}`}, {x: "weight", inset: 0.5}))
  ]
})