Plot.plot({
width: 928,
height: 500,
x: { label: null },
y: { label: "PERCENT", tickFormat: "s", tickSpacing: 50 },
color: {
scheme: "Spectral",
legend: "ramp",
width: 340,
label: "Age (years)"
},
marks: [
Plot.barY(tidy, {
filter: (d) => d.age !== "40-49",
...Plot.stackY({
order: (a, b) => (a === "40-49" ? 1 : 0),
x: "state",
y: "population",
fill: "age",
sort: { color: null, x: "-y" },
offset: "normalize",
channels: {
customY: {
label: "Percent",
value: "population"
}
},
tip: {
format: {
customY: true
}
}
})
})
]
})