Public
Edited
Apr 27, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = FileAttachment("us-population-state-age.csv")
.csv({ typed: true })
Insert cell
Insert cell
Insert cell
Inputs.table(data)
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.barY(data, { x: "name", y: "20-29" })]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
y: {
transform: (d) => d / 1_000_000
},
marks: [Plot.barY(data, { x: "name", y: "20-29" })]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barY(data, { x: "name", y: "20-29" })

]
})
Insert cell
// ... your code here
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [Plot.barY(data, { x: "name", y: "20-29" })]
})
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, { x: "name", y: "20-29", sort: { x: "y", reverse: true } })
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, {
x: "name",
y: "20-29",
sort: { x: "y", reverse: true },
fill: "goldenrod"
})
]
})
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, {
x: "name",
y: "20-29",
sort: { x: "y", reverse: true },
fill: (d) => (d["20-29"] > 1_200_000 ? "salmon" : "dodgerblue")
})
]
})
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, {
x: "name",
y: "20-29",
sort: { x: "y", reverse: true },
fill: (d) => (d["name"] === "VA" ? "salmon" : "dodgerblue")
})
]
})
Insert cell
Insert cell
Insert cell
Inputs.table(data)
Insert cell
Insert cell
Insert cell
ageRangeToFocus = "<10"
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, {
x: "name",
y: ageRangeToFocus,
sort: { x: "y", reverse: true },
fill: (d) => (d["name"] === "VA" ? "salmon" : "dodgerblue")
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
ageRange
Insert cell
viewof ageRange = Inputs.select(
["<10", "10-19", "20-29", "30-39", "40-49", "50-59", "60-69", "70-79", "≥80"],
{ label: "Select an age range" }
)
Insert cell
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, {
x: "name",
y: ageRange,
sort: { x: "y", reverse: true },
fill: (d) => (d["name"] === "VA" ? "salmon" : "dodgerblue")
})
]
})
Insert cell
Insert cell
Insert cell
viewof sort_toggle = Inputs.toggle({
label: "Sort States by Magnitude",
value: true
})
Insert cell
Plot.plot({
width: 1200,
marginLeft: 80,
x: {
label: "State"
},
y: {
label: "↑Million People",
transform: (d) => d / 1_000_000
},
marks: [
Plot.barY(data, {
x: "name",
y: ageRange,
sort: sort_toggle ? { x: "y", reverse: true } : "",
fill: (d) => (d["name"] === "VA" ? "salmon" : "dodgerblue")
})
]
})
Insert cell
Insert cell
Insert cell
import {toc} from "@nebrius/indented-toc"
Insert cell
import {imageToDo} from "@clokman/student-blocks"
Insert cell
imageToDo
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