# Can I use Plot.text to show the count of a group?

**URL:** <https://talk.observablehq.com/t/can-i-use-plot-text-to-show-the-count-of-a-group/5442>\
**Category:** Help\
**Created:** [August 10, 2021, 7:08pm UTC](https://talk.observablehq.com/t/can-i-use-plot-text-to-show-the-count-of-a-group/5442 "2021-08-10T19:08:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrislkeller](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/chrislkeller/32/4259_2.png) [@chrislkeller](https://talk.observablehq.com/u/chrislkeller)\
**Post date:** [August 10, 2021, 7:08pm UTC](https://talk.observablehq.com/t/can-i-use-plot-text-to-show-the-count-of-a-group/5442/1 "2021-08-10T19:08:14Z")

</div>

Hi… Was using Plot to do some analysis of PPP loans and I wanted to group by industry sector, which I was able to figure out.

Displaying the count for each sector using Plot.text on the fly proved to be a bit more challenging. Was wondering if there was a more efficient solution than what I arrived at [here](https://observablehq.com/@chrislkeller/analysis-of-new-mexico-ppp-data#cell-420).

Essentially I mapped the loans by name of the sector in another cell

```auto
sector_count = d3.rollup(
  ppp_loans,
  (v) => v.length,
  (d) => d.name
)

```

And then accessed the appropriate element based on the name

```auto
    Plot.text(ppp_loans, {
      x: 0,
      y: "name",
      text: (d) => sector_count.get(d.name),
      dx: 25
    }),

```

Is there a way to do this right from Plot.text()?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [August 10, 2021, 7:16pm UTC](https://talk.observablehq.com/t/can-i-use-plot-text-to-show-the-count-of-a-group/5442/2 "2021-08-10T19:16:41Z")

</div>

Try this:

```auto
Plot.text(ppp_loans, Plot.groupY({text: "count"}, {x: 0, y: "name", dx: 25}))

```

---

<div class="post-metadata">

**Author:** ![chrislkeller](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/chrislkeller/32/4259_2.png) [@chrislkeller](https://talk.observablehq.com/u/chrislkeller)\
**Post date:** [August 10, 2021, 7:28pm UTC](https://talk.observablehq.com/t/can-i-use-plot-text-to-show-the-count-of-a-group/5442/3 "2021-08-10T19:28:32Z")

</div>

Yeah, that worked @mbostock. Thank you.

So working backwards, [in the docs](https://observablehq.com/@observablehq/plot-group#cell-52) where it says

`Each grouped output channel (the keys of the object passed as the first argument to the group transform) has an associated reducer which controls how the summary value for each group is derived.`

groupX() and groupY() makes “count” and all the others available to access for free?

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [August 11, 2021, 7:29pm UTC](https://talk.observablehq.com/t/can-i-use-plot-text-to-show-the-count-of-a-group/5442/4 "2021-08-11T19:29:59Z")

</div>

The “count” here refers to a _reducer_ or aggregation method. It’s a way of deriving a single value, such as a count, from the set of values that correspond to each group (or bin). More details here:

> <https://github.com/observablehq/plot/blob/main/README.md#group>
