Plot.plot({
marks: [
Plot.barX(
penguins,
Plot.binX(
{ fill: "mean" },
{
x: "body_mass",
fill: "body_mass",
thresholds: (values) => {
const bins = simple.ckmeans(
values.filter((d) => d == +d),
thresholds
);
return d3.pairs(bins).map(([a, b]) => (d3.max(a) + d3.min(b)) / 2);
}
}
)
),
Plot.textX(
penguins,
Plot.binX(
{ text: "count" },
{
x: "body_mass",
thresholds: (values) => {
const bins = simple.ckmeans(
values.filter((d) => d == +d),
thresholds
);
return d3.pairs(bins).map(([a, b]) => (d3.max(a) + d3.min(b)) / 2);
},
fill: "white"
}
)
)
],
color: { scheme: "viridis", domain: [2700, 6000] },
width
})