{
const numformat = d3.format(".0f");
const text_paint = (result) => `Mean: ${numformat(result)}`;
const options = Plot.groupX(
{ y: "mean", text: "mean" },
{ x: "species", y: "body_mass_g", text: "body_mass_g" }
);
return Plot.plot({
marks: [
Plot.barY(penguins, {
...options,
stroke: "navy"
}),
Plot.text(
penguins,
Plot.map(
{
text: (v) => v.map(text_paint)
},
{
...options,
lineAnchor: "bottom",
dy: -5
}
)
),
Plot.ruleY(penguins, {
...Plot.groupZ(
{
y: "mean"
},
options
),
x: null
}),
Plot.text(
penguins,
Plot.map(
{ text: (v) => v.map(text_paint) },
{
...Plot.groupZ(
{
y: "mean",
text: "mean"
},
options
),
x: null,
lineAnchor: "bottom",
dy: -5
}
)
)
]
});
}