Public
Edited
Feb 20
Insert cell
md`# Classifying the Percent of Women over 25 with Bachelor's Degrees in Iowa Counties`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
Counties = FileAttachment("US_County_2020_WGS84.json").json()
Insert cell
county_features = topojson.feature(Counties, Counties.objects.US_County_2020_WGS84)
Insert cell
csv_data = d3.csvParse(await FileAttachment("Education.csv").text(),({STATE, COUNTY, ASP2E032, ASP2E019}) => STATE === "Iowa" ? [COUNTY, (+ASP2E032/+ASP2E019)*100] : null
).filter(d => d);
Insert cell
csv_data_objects = d3.csvParse(await FileAttachment("Education.csv").text(), d3.autoType)
.map(({ STATE, COUNTY, ASP2E032, ASP2E019 }) =>
STATE === "Iowa" ? {County: COUNTY, pctWomenWithBachelors: (+ASP2E032/+ASP2E019)*100} : null
)
.filter(d => d);
Insert cell
viewof bins = Inputs.range([0, 40], {step: 1, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(csv_data_objects, Plot.binX({y: "count"}, {x: "pctWomenWithBachelors", thresholds: bins})),
Plot.ruleY([0])
]
})
Insert cell
pctWomenWithBahcelors = Array.from(csv_data.values(), d => d[1])
Insert cell
data = Object.assign(new Map(csv_data), {title: ["Percent of Women in Iowa with a Bachelor's Degree: 25 and Older"]})
Insert cell
md`# Linear Scale (Unclassed)`
Insert cell
unclassed = d3.scaleLinear()
.domain(d3.extent(pctWomenWithBahcelors))
.range(["#fee6ce", "#e6550d"])
Insert cell
chart(numericSort(pctWomenWithBahcelors), unclassed)
Insert cell
md`# Quantile Classification`
Insert cell
quantile = d3.scaleQuantile()
.domain(pctWomenWithBahcelors)
.range(["#f2f0f7", "#cbc9e2", "#9e9ac8", "#6a51a3"])
Insert cell
chart(numericSort(pctWomenWithBahcelors), quantile)
Insert cell
md`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks = simple.ckmeans(pctWomenWithBahcelors, 4).map(v => v.pop())
Insert cell
jenks = d3
.scaleThreshold()
.domain(naturalbreaks)
.range(["#edf8e9", "#bae4b3", "#74c476", "#31a354", "#006d2c"])
Insert cell
chart(numericSort(pctWomenWithBahcelors), jenks)
Insert cell
md`# Equal Interval Classification (Quantize)`
Insert cell
quantize = d3.scaleQuantize()
.domain([d3.min(pctWomenWithBahcelors),d3.max(pctWomenWithBahcelors)])
.range(["#eff3ff", "#bdd7e7", "#6baed6", "#3182bd", "#08519c"])
Insert cell
chart(numericSort(pctWomenWithBahcelors), quantize)
Insert cell
md`# Threshold`
Insert cell
threshold = d3.scaleThreshold()
.domain([14, 18, 21, 27])
.range(["#fee5d9", "#fcae91", "#fb6a4a", "#de2d26", "#a50f15"])
Insert cell
d3.min(pctWomenWithBahcelors)
Insert cell
d3.max(pctWomenWithBahcelors)
Insert cell
chart(numericSort(pctWomenWithBahcelors), threshold)
Insert cell
showScaleGrouping(pctWomenWithBahcelors, {
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