Public
Edited
Feb 20
Insert cell
md`# Black and African American Populations in Minnesota: Classification and Colors`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
Minnesota = FileAttachment("MN_2020_Project.json").json()
Insert cell
Minnesota_features = topojson.feature(Minnesota, Minnesota.objects.MN_2020_Project_ExportFeatures)
Insert cell
csv_data = d3.csvParse(await FileAttachment("MN Race.csv").text(),({GISJOIN, U7B001, U7B004}) => [GISJOIN, [U7B001, +100*U7B004/+U7B001]])
Insert cell
csv_data_objects = Object.assign((d3.csvParse(await FileAttachment("MN Race.csv").text(), d3.autoType)).map(({GISJOIN, U7B001, U7B004}) => ({GISJOIN: +GISJOIN, BlackPopulationPct: +100*U7B004/+U7B001})))
Insert cell
viewof bins = Inputs.range([0, 20], {step: 1, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(csv_data_objects, Plot.binX({y: "count"}, {x: "BlackPopulationPct", thresholds: bins})),
Plot.ruleY([0])
]
})
Insert cell
BlackPopulationPct = Array.from(csv_data.values(), d => d[1][1])
Insert cell
data = Object.assign(new Map(csv_data), {title: ["Black Population, Black Population Pct"]})
Insert cell
md`# Linear Scale (Unclassed)`
Insert cell
linear = d3.scaleLinear()
.domain(d3.extent(BlackPopulationPct))
.range(["#fee0d2", "#de2d26"])
Insert cell
chart(numericSort(BlackPopulationPct), linear)
Insert cell
md`# Quantile Classification`
Insert cell
quantile = d3.scaleQuantile()
.domain(BlackPopulationPct)
.range(["#f7fcb9", "#addd8e", "#31a354"])
Insert cell
chart(numericSort(BlackPopulationPct), quantile)
Insert cell
md`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks = simple.ckmeans(BlackPopulationPct, 3).map(v => v.pop())
Insert cell
jenks = d3
.scaleThreshold()
.domain(naturalbreaks)
.range(["#fee0d2", "#fc9272", "#de2d26"])
Insert cell
chart(numericSort(BlackPopulationPct), jenks)
Insert cell
md`# Equal Interval Classification (Quantize)`
Insert cell
quantize = d3.scaleQuantize()
.domain([d3.min(BlackPopulationPct),d3.max(BlackPopulationPct)])
.range(["#fde0dd", "#fa9fb5", "#c51b8a"])
Insert cell
chart(numericSort(BlackPopulationPct), quantize)
Insert cell
md`# Threshold`
Insert cell
threshold = d3.scaleThreshold()
.domain([0.05, 0.1, 0.2])
.range(["white", "#99d594", "green"])
Insert cell
chart(numericSort(BlackPopulationPct), threshold)
Insert cell
showScaleGrouping(BlackPopulationPct, {
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