Published
Edited
Mar 3, 2021
Insert cell
md`# Second Exercise`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
Illinois= FileAttachment("ILwithcount (2).json").json()
Insert cell
county_features = topojson.feature(Illinois, Illinois.objects.ILwithcount)
Insert cell
csv_data = d3.csvParse(await FileAttachment("ILwithcountplsberight (1).csv").text(),({GEOID, acresoffarmlandp4_Value, acresoffarmlandp4_land_acres}) => [GEOID, [+acresoffarmlandp4_Value, +acresoffarmlandp4_Value/+acresoffarmlandp4_land_acres]])
Insert cell
farmpct = Array.from(csv_data.values(), d => d[1][1])
Insert cell
data = Object.assign(new Map(csv_data), {title: ["Percent Population of Alaska: 5 and Younger"]})
Insert cell
md`# Linear Scale (Unclassed)`
Insert cell
linear = d3.scaleLinear()
.domain([d3.min(farmpct),d3.max(farmpct)])
.range(["#efedf5", "#756bb1"])
Insert cell
chart(numericSort(farmpct), linear)
Insert cell
md`# Quantile Classification`
Insert cell
quantile = d3.scaleQuantile()
.domain(farmpct)
.range(["#f2f0f7", "#cbc9e2","#9e9ac8","#756bb1","#54278f"])
Insert cell
chart(numericSort(farmpct), quantile)
Insert cell
md`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks = simple.ckmeans(farmpct,5 ).map(v => v.pop())
Insert cell
jenks = d3
.scaleThreshold()
.domain(naturalbreaks)
.range([ "#efedf5","#bcbddc", "#756bb1"])
Insert cell
chart(numericSort(farmpct), jenks)
Insert cell
md`# Equal Interval Classification (Quantize)`
Insert cell
quantize = d3.scaleQuantize()
.domain([d3.min(farmpct),d3.max(farmpct)])
.range(["#f2f0f7", "#cbc9e2", "#9e9ac8","#756bb1","#54278f"])
Insert cell
chart(numericSort(farmpct), quantize)
Insert cell
md`# Threshold`
Insert cell
threshold = d3.scaleThreshold()
.domain([0.06444582814445828, 0.09325355890241387, 0.12106180453143853])
.range(["#efedf5", "#bcbddc", "#756bb1"])
Insert cell
chart(numericSort(farmpct), threshold)
Insert cell
showScaleGrouping(farmpct, {
scaleQuantile: quantile,
scaleThreshold: threshold,
scaleJenks: jenks,
scaleQuantize: quantize,
scaleQuantizeNice: quantize.copy().nice()
})
Insert cell
md`# Annex`
Insert cell
Insert cell
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
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