Public
Edited
May 19
Insert cell
Insert cell
import {vl} from "@vega/vega-lite-api-v5"
Insert cell
import {printTable} from "@uwdata/data-utilities"
Insert cell
data = FileAttachment("census2000-1.csv").csv()
Insert cell
printTable(data.slice(0,5))
Insert cell
vl.markBar()
.data(data)
.transform(
vl.calculate("toNumber(datum.People) / 1000000").as("PeopleNum"),
// for the mirroring effect used to compare the two years' populations across the same age group
vl.calculate("datum.Year === '1900' ? -datum.PeopleNum : datum.PeopleNum").as("MirroredPopulation"))
.encode(
vl.y()
.fieldN("Age")
.sort([
"0", "5", "10", "15", "20", "25", "30", "35", "40", "45",
"50", "55", "60", "65", "70", "75", "80", "85", "90"]),
vl.x()
.fieldQ("MirroredPopulation")
.scale({ domain: [-25, 25] })
.axis({
title: "Population (millions)",
format: ",",
labelExpr: "abs(datum.value)" }),
vl.color().fieldN("Year")
)
.title("How has the distribution of the U.S. population by age changed between 1900 and 2000?")
.width(500)
.height(600)
.render()
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