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:

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:

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:

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.
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:
I can overwrite the x definition to get what I want, so it’s possible but awkward:
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):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:
And here the problem is that neither
normalize: truenornormalize: "z"do what I want, because I want to normalize to the facet. Maybenormalize: "facet"should be an option? That’s certainly easy to implement.