Plot.plot({
x: {
axis: null,
domain: stateage.ages
},
y: {
grid: true,
tickFormat: "s"
},
color: {
domain: stateage.ages,
scheme: "spectral",
legend: true,
marginTop: 100,
marginRight: 100,
marginBottom: 100,
marginLeft: 100,
},
fx: {
domain: d3.groupSort(stateage, v => d3.sum(v, d => -d.population), d => d.state).slice(0, 6),
label: null,
tickSize: 6
},
style: {
legend: {
marginLeft: 60
},
},
facet: {
data: stateage,
x: "state"
},
marks: [
Plot.barY(stateage, {x: "age", y: "population", fill: "age", title: "age"}),
Plot.ruleY([0])
]
})