Skip to content

How to aggregate other channels when grouping? #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mbostock opened this issue Mar 22, 2021 · 3 comments
Closed

How to aggregate other channels when grouping? #265

mbostock opened this issue Mar 22, 2021 · 3 comments
Labels
question Further information is needed

Comments

@mbostock
Copy link
Member

This works, the definition of the text channel is awkward:

untitled-46

Plot.plot({
  marks: [
    Plot.barX(penguins, Plot.stackX(Plot.groupZX({fill: "species", normalize: true}))),
    Plot.text(penguins, Plot.stackXMid(Plot.groupZX({text: ([d]) => d.species, z: "species", normalize: true}))),
    Plot.ruleX([0, 100])
  ]
})

I’d prefer something like this:

Plot.plot({
  marks: [
    Plot.barX(penguins, Plot.stackX(Plot.groupZX({fill: "species", normalize: true}))),
    Plot.text(penguins, Plot.stackXMid(Plot.groupZX({text: "species", z: "species", normalize: true}))),
    Plot.ruleX([0, 100])
  ]
})

But this would require that the group transform know that text is a channel, and to aggregate it (by selecting the first value, presumably). And currently the group transform doesn’t need to know how to interpret the passed-in options, other than the ones that are specifically eligible for grouping (namely x, y, z, fill, stroke).

@mbostock mbostock added the question Further information is needed label Mar 22, 2021
@Fil
Copy link
Contributor

Fil commented Mar 23, 2021

text and title should be eligible to Z?

@mbostock
Copy link
Member Author

Fixed in #272.

@oluckyman
Copy link

oluckyman commented Jul 23, 2021

Just for the reference put an up to date working example here (as I landed on this issue while googling for an example of labelling sections on a stacked bar chart)
image

Plot.plot({
  marks: [
    Plot.barX(
      dtDiagnostics,
      Plot.groupY({ x: "count" }, { y: "subject", fill: "class" })
    ),
    Plot.text(
      dtDiagnostics,
      Plot.stackX(
        Plot.groupY(
          { x: "count" },
          { y: "subject", z: "class", fill: "white", text: (d) => d[0].class }
        )
      )
    )
  ],
  marginLeft: 100
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is needed
Projects
None yet
Development

No branches or pull requests

3 participants