# Getting values for proportion reducers in Plot

**URL:** <https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040>\
**Category:** Help\
**Created:** [January 6, 2022, 5:42pm UTC](https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040 "2022-01-06T17:42:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwhitaker](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mwhitaker/32/5969_2.png) [@mwhitaker](https://talk.observablehq.com/u/mwhitaker)\
**Post date:** [January 6, 2022, 5:42pm UTC](https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040/1 "2022-01-06T17:42:32Z")

</div>

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:

> **[Bins and proportions for facetted data](https://observablehq.com/d/c1ac45ab25a21e9f)**
>
> Using a slimmed-down dataset from the Bin Transform example Is it possible to access the values of the fill channel for use in title? I'd like to show the proportions generated by either proportion or proportion-facet.

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

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [January 6, 2022, 6:38pm UTC](https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040/2 "2022-01-06T18:38:24Z")

</div>

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

```auto
      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?

---

<div class="post-metadata">

**Author:** ![mwhitaker](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mwhitaker/32/5969_2.png) [@mwhitaker](https://talk.observablehq.com/u/mwhitaker)\
**Post date:** [January 6, 2022, 7:34pm UTC](https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040/3 "2022-01-06T19:34:31Z")

</div>

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

Michael

---

<div class="post-metadata">

**Author:** ![fcontrepois](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fcontrepois/32/6270_2.png) [@fcontrepois](https://talk.observablehq.com/u/fcontrepois)\
**Post date:** [April 3, 2023, 4:34pm UTC](https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040/4 "2023-04-03T16:34:51Z")

</div>

> [@mwhitaker](#):
>
> I know how to access the groups and compute summary stats

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

---

<div class="post-metadata">

**Author:** ![mwhitaker](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mwhitaker/32/5969_2.png) [@mwhitaker](https://talk.observablehq.com/u/mwhitaker)\
**Post date:** [April 3, 2023, 6:44pm UTC](https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040/5 "2023-04-03T18:44:49Z")

</div>

You expect me to remember stuff from a year ago? 😉  
The Plot API has changed since my post, but If you look at the last example from [Bin Transform](https://observablehq.com/@observablehq/plot-bin?collection=@observablehq/plot), 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.

```auto
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}))
  ]
})

```
