chart = Plot.plot({
y: {
grid: true,
percent: true
},
marks: [
Plot.barY(
penguins,
Plot.groupX({ y: "proportion" }, { x: "species", fill: "sex" })
),
Plot.textY(
penguins,
Plot.stackY(
Plot.groupX(
{
y: "proportion",
text: (d) => d3.format("0.2%")(d.length / penguins.length)
},
{ x: "species", z: "sex" }
)
)
),
Plot.ruleY([0])
]
})