Skip to content

“Zero-dimensional” group and more flexible normalization… #261

@mbostock

Description

@mbostock

I’m trying to make a stacked bar chart of Penguins by sex using the group transform. I can do this using Plot.groupX, but it requires a dummy x definition:

untitled-43

Plot.plot({
  y: {
    grid: true
  },
  marks: [
    Plot.barY(penguins, Plot.stackY(Plot.groupX({x: () => 1, fill: "sex", normalize: true}))),
    Plot.ruleY([0])
  ]
})

I can overwrite the x definition to get what I want, so it’s possible but awkward:

untitled-42

Plot.plot({
  y: {
    grid: true
  },
  marks: [
    Plot.barY(penguins, Plot.stackY({...Plot.groupX({x: () => 1, fill: "sex", normalize: true}), x: null})),
    Plot.ruleY([0])
  ]
})

What I want is some way for groupX’s x to be optional (maybe I want it to default to undefined, rather than defaulting to identity, but I suppose having it default to identity would be okay if I can say x: null):

Plot.plot({
  y: {
    grid: true
  },
  marks: [
    Plot.barY(penguins, Plot.stackY(Plot.groupX({fill: "sex", normalize: true}))),
    Plot.ruleY([0])
  ]
})

I’m not sure “groupX” is still the right name for this transform, but maybe it‘s fine, since it will output frequency to the y channel which is what I want.

The next thing I want is for this to work with faceting:

untitled-44

Plot.plot({
  y: {
    grid: true
  },
  facet: {
    data: penguins,
    x: "species"
  },
  marks: [
    Plot.barY(penguins, Plot.stackY({
      ...Plot.groupX({
        x: () => 1, // TODO
        fill: "sex",
        order: "z",
        normalize: true
      }),
      x: null
    })),
    Plot.ruleY([0])
  ]
})

And here the problem is that neither normalize: true nor normalize: "z" do what I want, because I want to normalize to the facet. Maybe normalize: "facet" should be an option? That’s certainly easy to implement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions