Published
Edited
Sep 27, 2021
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
(2500.5234)
Insert cell
Insert cell
Insert cell
color = d3.scaleOrdinal(d3.schemeTableau10)
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
H = width * 1 / 3
Insert cell
path = d3.geoPath().projection(testprojection)
Insert cell
counties = topojson.feature(sc, sc.objects.counties)
Insert cell
Insert cell
testprojection = d3.geoIdentity()
.reflectY(true)
.fitSize([width, width * 1/3], counties)
Insert cell
Insert cell
Insert cell
code = {
if(divisions=="counties" && place!=null)
return place.COUNTYFP
else if (place!= null)
return place.COUSUBFP
else
return null
}
Insert cell
Insert cell
Insert cell
Insert cell
statedata = [JSON.parse('{"Total_2010": 4625364, "White_2010": 3060000, "Black_2010": 1290684, "AAIAN_2010": 19524, "Asian_2010": 59051, "NHPI_2010": 2706, "Other_2010": 113464, "Two_or_more_2010": 79935, "Hispanic_2010": 235682, "Total_2020": 5118425, "White_2020": 3243442, "Black_2020": 1280531, "AAIAN_2020": 24303, "Asian_2020": 90466, "NHPI_2020": 3431, "Other_2020": 177876, "Two_or_more_2020": 298376, "Hispanic_2020": 352838, "Other_combi__2010": 135694, "Other_combi__2020": 205610}')]
Insert cell
Insert cell
place
Insert cell
Insert cell
data
Insert cell
mapval = (divisions=="places") ? "COUSUBA" : "COUNTYA"
Insert cell
pctchangemap = d3.rollup(data, v => d3.sum(v, d => (d.Total_2020-d.Total_2010)/(d.Total_2010)), d => d[mapval])
Insert cell
Math.max(...pctchangemap.values())
Insert cell
mapcol = {
if(mapval=="COUNTYA")
return d3.scaleDiverging([-0.4, 0, 0.4], d3.interpolateRdYlGn)
else
return d3.scaleDiverging([-1.5, 0, 1.5], d3.interpolateRdYlGn)
}
Insert cell
data = {
if (divisions == "places")
return FileAttachment("data@5.csv").csv()
else
return FileAttachment("county_data@4.csv").csv()
}
Insert cell
countydata=FileAttachment("county_data@4.csv").csv()
Insert cell
d3 = require("d3@7")
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
import {radio, select} from "@jashkenas/inputs"
Insert cell
topojson = require("topojson-client@3")
Insert cell
import {ramp} from "@mbostock/color-ramp"
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