# Plot Group Transform Behavior: Default Channel vs. Array of Objects

**URL:** <https://talk.observablehq.com/t/plot-group-transform-behavior-default-channel-vs-array-of-objects/7259>\
**Category:** Help\
**Created:** [November 8, 2022, 7:12pm UTC](https://talk.observablehq.com/t/plot-group-transform-behavior-default-channel-vs-array-of-objects/7259 "2022-11-08T19:12:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarioDelgadoSr](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mariodelgadosr/32/1828_2.png) [@MarioDelgadoSr](https://talk.observablehq.com/u/MarioDelgadoSr)\
**Post date:** [November 8, 2022, 7:12pm UTC](https://talk.observablehq.com/t/plot-group-transform-behavior-default-channel-vs-array-of-objects/7259/1 "2022-11-08T19:12:53Z")

</div>

Plot’s group’s transform appears to behave differently depending on the format of the data input; default array vs array of objects.

Should we be taking into account the format of the data when specifying the parameter to the title option?

See [Plot Group Transform with Array of Objects Issue / Mario Delgado / Observable](https://observablehq.com/d/0dd33326af8f410e) for a reproduction of the issue.

---

<div class="post-metadata">

**Author:** ![camdecoster](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/camdecoster/32/6587_2.png) [@camdecoster](https://talk.observablehq.com/u/camdecoster)\
**Post date:** [November 8, 2022, 10:17pm UTC](https://talk.observablehq.com/t/plot-group-transform-behavior-default-channel-vs-array-of-objects/7259/2 "2022-11-08T22:17:21Z")

</div>

From my testing, it appears that the function you’re using to determine the `title` prop receives one of the elements from the data array. Therefore, if the elements are arrays, you can use map. If they’re objects, you can’t (but you can access the properties). This should work in the second example from your notebook:

```javascript
Plot.plot({
  marks: [
    Plot.barY(
      [{ a: "Y" }, { a: "N" }],
      Plot.groupX(
        { y: "count" },
        {
          x: "a",
          title: (group) => group.a
        }
      )
    )
  ]
})

```

---

<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:** [November 9, 2022, 9:41am UTC](https://talk.observablehq.com/t/plot-group-transform-behavior-default-channel-vs-array-of-objects/7259/3 "2022-11-09T09:41:29Z")

</div>

In a Plot.group (or Plot.bin) transform, you can set the title in two places:

- in the first part (the _outputs_), the title property describes a reducer that defines how a summary value is computed for each group. The reducer is applied on the grouped values from the title channel—or, by default, to the grouped values from the data array.
- in the second part (the _options_), the title property describes the _input_ title channel, indexed on the data.

So if you have, e.g.:

```auto
Plot.group({
    title: group => d3.mode(group)
  },
  {
    title: "a"
  }
)

```

it is equivalent to:

```auto
Plot.group({
    title: group => d3.mode(group, d => d.a)
  },
  {}
)

```

In your notebook, however, no reducer is defined for the title group option, so it defaults to a function that counts the occurrences in each group and returns the top 5, together with a count. Which is why you see “Y (1)”. This function is a special case (only used as the [default title reducer](https://github.com/observablehq/plot/blob/977e0118dad0f05158dbc3c0cab5f92047f449fd/src/transforms/group.js#L174)), which I realize has not been documented yet.

For reference:

- [Group Transform / Observable Plot / Observable / Observable](https://observablehq.com/@observablehq/plot-group)
- [plot/README.md at main · observablehq/plot · GitHub](https://github.com/observablehq/plot/blob/main/README.md#group)
- [document reduceTitle by Fil · Pull Request #1105 · observablehq/plot · GitHub](https://github.com/observablehq/plot/pull/1105/files)

---

<div class="post-metadata">

**Author:** ![MarioDelgadoSr](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mariodelgadosr/32/1828_2.png) [@MarioDelgadoSr](https://talk.observablehq.com/u/MarioDelgadoSr)\
**Post date:** [November 9, 2022, 10:30am UTC](https://talk.observablehq.com/t/plot-group-transform-behavior-default-channel-vs-array-of-objects/7259/4 "2022-11-09T10:30:03Z")

</div>

Thanks for detailed explanation.
