Published
Edited
Apr 4, 2022
2 forks
13 stars
Insert cell
Insert cell
Plot.plot({
x: {
label: "Commute time (minutes) →",
ticks: 20
},
y: {
label: "↑ People (per 5 minute interval)",
transform: (n) =>
n * 5 /* 5-minute intervals */ * 1000 /* data is in thousands */,
tickFormat: "~s",
nice: true,
grid: true
},
caption: "Histogram of travel time (to work), US 2000 census.",
marks: [
Plot.rectY(commute, {
x1: "lo",
x2: "hi",
y: (d) => d.people / (d.hi - d.lo),
fill: "#aaa",
insetRight: 1,
title: (d) =>
`${new Intl.NumberFormat("en-US").format(d.people / 1000)} million people\nspend ${d.lo} to ${d.hi} minutes\nto commute to work.`
}),
Plot.text(commute, {
filter: "annotation",
text: "annotation",
x: "hi",
y: (d) => d.people / (d.hi - d.lo),
dx: 2,
dy: 8,
textAnchor: "start"
}),
Plot.ruleY([0])
],
height: 240,
width: 400
})
Insert cell
commute = d3.csvParse(
`lo,hi,people,annotation
0,5,4180
5,10,13687
10,15,18618
15,20,19634
20,25,17981
25,30,7190
30,35,16369,"← For 16.4 million workers, commuting takes 30 to 35 min."
35,40,3212
40,45,4122
45,60,9200
60,90,6461
90,150,3435
`,
d3.autoType
)
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more