Unlisted
Edited
Apr 21, 2023
Insert cell
Insert cell
Plot.plot({
x: {
domain: stateage.ages, // in age order
label: "Age range (years) →",
labelAnchor: "right"
},
y: {
label: "↑ Population (%)",
percent: true,
grid: true
},
marks: [
Plot.ruleY([0]),
Plot.line(stateage, Plot.normalizeY("sum", {x: "age", y: "population", z: "state", strokeWidth: 1}))
]
})
Insert cell
stateage = FileAttachment("us-population-state-age.csv").csv({typed: true}).then((data) => {
const ages = data.columns.slice(1); // convert wide data to tidy data
return Object.assign(ages.flatMap(age => data.map((d) => ({state: d.name, age, population: d[age]}))), {ages});
});
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more