Radial Stacked Bars
The population of every US state by age, as bars spread and stacked and then drawn in polar coordinates. After D3.
js
const wide = await d3.csv("/data/us-population-state-age.csv", d3.autoType);
const ages = wide.columns.slice(1);
const data = wide.flatMap((d) => ages.map((age) => ({state: d.name, age, population: d[age]})));
const renderer = cm.svg({width: 928, height: 928});
const root = cm.flow().renderer(renderer);
root
.data(data)
.transform(cm.encode, {
x: "state",
y: "population",
fill: "age",
})
.transform(cm.spreadX)
.transform(cm.stackY, {order: ages})
.transform(cm.polar, {
innerRadius: 180 / 454,
margin: 10,
x: {axis: true},
y: {axis: true, ticks: 5, tickFormat: "s"},
fill: {range: d3.schemeSpectral[ages.length]},
})
.add(cm.arc);
root.render();
document.body.append(renderer.node());