{
const xy = Plot.normalizeX({basis: "sum", z: "state", x: "population", y: "state"});
return Plot.plot({
height: 660,
grid: true,
x: {
axis: "top",
label: "Percent (%) →",
transform: d => d * 100
},
y: {
domain: d3.groupSort(stateage, g => -g.find(d => d.age === "≥80").population / d3.sum(g, d => d.population), d => d.state),
axis: null
},
color: {
scheme: "spectral",
domain: stateage.ages
},
marks: [
Plot.ruleX([0]),
Plot.ruleY(stateage, Plot.groupY({x1: "min", x2: "max"}, xy)),
Plot.dot(stateage, {...xy, fill: "age"}),
Plot.text(stateage, Plot.selectMinX({...xy, textAnchor: "end", dx: -6, text: "state"}))
]
});
}