Plot.plot({
marginLeft: 100,
padding: 0,
x: {
round: true,
grid: true
},
fy: {
label: null,
domain: d3.groupSort(athletes, g => d3.median(g, d => d.weight), d => d.sport)
},
color: {
scheme: "YlGnBu"
},
facet: {
data: athletes,
marginLeft: 100,
y: "sport"
},
marks: [
Plot.barX(athletes,
Plot.binX(
{
fill: prop,
title: {
scope: prop === "proportion" ? "data" : prop === "proportion-facet" ? "facet" : undefined,
reduce: (I, V, basis) => basis === undefined
? I.length
: `group length: ${I.length}, sum: ${d3.sum(I, i => V[i].weight)}, ${prop}: ${I.length / basis}`
}
},
{
x: "weight",
inset: 0.5
}
)
)
]
})