Public
Edited
Feb 21
Insert cell
md`# Assignment 2: Classification and Colors`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
block_group = FileAttachment("IA_block_group.json").json()
Insert cell
blkgrp_features = topojson.feature(block_group, block_group.objects.IA_block_group)
Insert cell
csv_data = d3.csvParse(await FileAttachment("HH_info.csv").text(),({GISJOIN, STATE, COUNTY, BLKGRPA, TRACTA, Total_HH, Family_HH, Nonfamily_HH}) => [GISJOIN, +Family_HH/+Total_HH])
Insert cell
normalized_data = Object.assign((d3.csvParse(await FileAttachment("HH_info.csv").text(), d3.autoType)).map(({GISJOIN, STATE, COUNTY, BLKGRPA, TRACTA, Total_HH, Family_HH, Nonfamily_HH}) => ({GISJOIN: +GISJOIN, HH_pct: +Family_HH/+Total_HH})))
Insert cell
md`## Defining Normalized Variable`
Insert cell

HH_pct = Array.from(csv_data.values(), d => d[1])
Insert cell
md`## Creating Histogram`
Insert cell
viewof bins = Inputs.range([0, 10], {step: 1, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(normalized_data, Plot.binX({y: "count"}, {x: "HH_pct", thresholds: bins})),
Plot.ruleY([0])
]
})
Insert cell
data = Object.assign(new Map(csv_data), {title: ["Percent Family Household in Iowa"]})
Insert cell
md`# Linear Scale (Unclassed)`
Insert cell
md`## Creating Unclassed Map`
Insert cell
unclassed = d3.scaleLinear()
.domain(d3.extent(HH_pct))
.range(["#fee8c8", "#e34a33"])
Insert cell
chart(numericSort(HH_pct), unclassed)
Insert cell
md`# Quantile Classification`
Insert cell
md`## Creating Quantile Classification`
Insert cell
quantile = d3.scaleQuantile()
.domain(HH_pct)
.range(["#fef0d9", "#fdcc8a", "#fc8d59", "#d7301f"])
Insert cell
chart(numericSort(HH_pct), quantile)
Insert cell
md`# Jenks Natural Breaks Classification`
Insert cell
md`## Creating Natural Breaks Classification`
Insert cell
naturalbreaks = simple.ckmeans(HH_pct, 5).map(v => v.pop())
Insert cell
jenks = d3
.scaleThreshold()
.domain(naturalbreaks)
.range(["#fef0d9", "#fdcc8a", "#fc8d59", "#e34a33", "#b30000"])
Insert cell
chart(numericSort(HH_pct), jenks)
Insert cell
md`# Equal Interval Classification (Quantize)`
Insert cell
md`## CreatingEqual Interval Classification (Quantize)`
Insert cell
quantize = d3.scaleQuantize()
.domain([d3.min(HH_pct),d3.max(HH_pct)])
.range(["#fee8c8", "#fdbb84", "#e34a33"])
Insert cell
chart(numericSort(HH_pct), quantize)
Insert cell
md`# Threshold`
Insert cell
md`## Creating Manual Classification (Threshold)`
Insert cell
threshold = d3.scaleThreshold()
.domain([0.3, 0.6, 0.9])
.range(["#fef0d9", "#fdcc8a", "#fc8d59", "#d7301f"])
Insert cell
chart(numericSort(HH_pct), threshold)
Insert cell
showScaleGrouping(HH_pct, {
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