Public
Edited
Feb 22, 2023
Insert cell
md`# GEOG:3540 Assignment #2 Classification and Colors`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
California = FileAttachment("GEOG3540_Assignment_1_California.json").json()
Insert cell
county_features = topojson.feature(California, California.objects.GEOG3540_Assignment_1_California)
Insert cell
csv_data = d3.csvParse(await FileAttachment("GEOG3540_Assignment_1_California_Census.csv").text(),({COUNTYFP10, Native, Total}) => [COUNTYFP10, Native, Total]])
Insert cell
csv_data_objects = Object.assign((d3.csvParse(await FileAttachment("GEOG3540_Assignment_1_California_Census.csv").text(), d3.autoType)).map(({COUNTYFP10, Native, Total}) => ({FIPS: +COUNTYFP10, pctNative: +Native/+Total})))
Insert cell
viewof bins = Inputs.range([0, 200], {step: 1, label: "Bins"})
Insert cell
Plot.plot({
marks: [
Plot.rectY(csv_data_objects, Plot.binX({y: "count"}, {x: "pctNative", thresholds: bins})),
Plot.ruleY([0])
]
})
Insert cell
nativepct = Array.from(csv_data.values(), d => d[1][0])
Insert cell
data = Object.assign(new Map(csv_data), {title: ["California Populaiton: Native American Percentage"]})
Insert cell
md`# Linear Scale (Unclassed)`
Insert cell
unclassed= d3.scaleLinear()
.domain(d3.extent(nativepct))
.range(["#e0f3db", "#43a2ca"])
Insert cell
chart(numericSort(nativepct), unclassed)
Insert cell
md`# Quantile Classification`
Insert cell
quantile = d3.scaleQuantile()
.domain(nativepct)
.range(["#e0ecf4", "#9ebcda", "#8856a7"])
Insert cell
chart(numericSort(nativepct), quantile)
Insert cell
md`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks = simple.ckmeans(nativepct, 3).map(v => v.pop())
Insert cell
jenks = d3
.scaleThreshold()
.domain(naturalbreaks)
.range(["#e0f3db", "#a8ddb5", "#43a2ca"])
Insert cell
chart(numericSort(nativepct), jenks)
Insert cell
md`# Equal Interval Classification (Quantize)`
Insert cell
quantize = d3.scaleQuantize()
.domain([d3.min(nativepct),d3.max(nativepct)])
.range(["#e0ecf4", "#9ebcda", "#8856a7"])
Insert cell
chart(numericSort(nativepct), quantize)
Insert cell
md`# Threshold`
Insert cell
threshold = d3.scaleThreshold()
.domain([.01, .05, 0.2])
.range(["#f0f9e8", "#bae4bc", "#7bccc4"])
Insert cell
chart(numericSort(nativepct), threshold)
Insert cell
showScaleGrouping(nativepct, {
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