Published
Edited
Apr 13, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
import {legend} from "@d3/color-legend"
Insert cell
format = d => `${d}%`
Insert cell
topojson = require("topojson-client@3")
Insert cell
california = FileAttachment("CA_county.json").json()
Insert cell
counties = topojson.feature(california, california.objects.CA_county)
Insert cell
csv_data = d3.csvParse(await FileAttachment("California_population.csv").text(),({GEOID, Total, from20to24, from25to34}) => [+GEOID, [((+from20to24 + +from25to34)/+Total)*100]])
Insert cell
data = Object.assign(new Map(csv_data), {title: ["Young people (age 20-34) percent"]})
Insert cell
youngpct = Array.from(csv_data.values(), d => d[1])
Insert cell
purples = [d3.color("#f2f0f7"), d3.color("#cbc9e2"), d3.color("#9e9ac8"), d3.color("#756bb1"),d3.color("#54278f")]
Insert cell
quantile = d3.scaleQuantile()
.domain(youngpct) // pass the whole dataset to a scaleQuantile’s domain
.range(purples)
Insert cell
width = 975
Insert cell
height = 610
Insert cell
margin = 100
Insert cell
//Stateplane - California Zone3 (EPSG:26943)
projection = d3.geoConicConformal()
.parallels([37 + 4 / 60, 38 + 26 / 60])
.rotate([120 + 30 / 60, 0]).fitExtent([[margin, margin], [width - margin, height - margin]], counties);
Insert cell
path = d3.geoPath().projection(projection);
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