Public
Edited
Feb 19
Insert cell
md`# Second Assignment on Observable: Classification and Colors`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
PMHD = FileAttachment("PMHDShapeFileProjected.json").json()
Insert cell
county_features = topojson.feature(PMHD, PMHD.objects.PMHDShapeFileProjected)
Insert cell
csv_data_PMHD = d3.csvParse(await FileAttachment("PMHDShapeFileProjected.csv").text(),({FIPS, CountyName, County_Val}) => [FIPS, CountyName, County_Val])
Insert cell
csv_data_objects = Object.assign((d3.csvParse(await FileAttachment("PMHDShapeFileProjected.csv").text(), d3.autoType)).map(({FIPS, CountyName, County_Val}) => ({FIPS, CountyName, County_Val})))
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: "County_Val", thresholds: bins})),
Plot.ruleY([0])
]
})
Insert cell
PMHDPerMonth = Array.from(csv_data_PMHD.values(), d => d[2])
Insert cell
data = Object.assign(new Map(csv_data_PMHD), {title: ["Poor Mental Health Days Per Month By County in Iowa"]})
Insert cell
md`# Linear Scale (Unclassed)`
Insert cell
linear = d3.scaleLinear()
.domain(d3.extent(PMHDPerMonth))
.range(["white", "blue"])
Insert cell
chart(numericSort(PMHDPerMonth), linear)
Insert cell
md`# Quantile Classification`
Insert cell
quantile = d3.scaleQuantile()
.domain(PMHDPerMonth)
.range(["#f7f4f9", "#dcb4d8", "#b75ab1", "#7b1fa2", "#4a1486"])
Insert cell
chart(numericSort(PMHDPerMonth), quantile)
Insert cell
md`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks = simple.ckmeans(PMHDPerMonth, 3).map(v => v.pop())
Insert cell
jenks = d3
.scaleThreshold()
.domain(naturalbreaks)
.range(["#fee5d9", "#fcae91", "#fb6a4a", "#de2d26", "#a50f15"])

Insert cell
chart(numericSort(PMHDPerMonth), jenks)
Insert cell
md`# Equal Interval Classification (Quantize)`
Insert cell
quantize = d3.scaleQuantize()
.domain([d3.min(PMHDPerMonth), d3.max(PMHDPerMonth)])
.range(["#fff5eb", "#fdbe85", "#fd8d3c", "#e6550d", "#a63603"]);
Insert cell
chart(numericSort(PMHDPerMonth), quantize)
Insert cell
md`# Threshold`
Insert cell
threshold = d3.scaleThreshold()
.domain([4.3, 4.5, 4.7, 4.9])
.range(["#ffffff", "#cdeac0", "#a3d9a5", "#6ec96e", "#2f7e41"])
Insert cell
chart(numericSort(PMHDPerMonth), threshold)
Insert cell
showScaleGrouping(PMHDPerMonth, {
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