🏠 back to Observable

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