Published
Edited
Mar 4, 2020
Insert cell
md`# Assignment One`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
nycounties = FileAttachment("NYCountiesWGS1984.json").json()
Insert cell
states_features = topojson.feature(nycounties, nycounties.objects.NYCountiesWGS1984)
Insert cell
csv_data = d3.csvParse(await FileAttachment("NYPOP@1.csv").text(),({FIPS, Population, Area}) => [FIPS,[ +Population,+Population/+Area]])
Insert cell
popdensity = Array.from(csv_data.values(), d => d[1][1])
Insert cell
linear = d3.scaleLinear()
.domain([0, d3.max(popdensity)])
.range(["white", "red"])
Insert cell
quantize = d3.scaleQuantize()
.domain(d3.extent(popdensity))
.range(["white", "pink", "red"])
Insert cell
quantile = d3.scaleQuantile()
.domain(popdensity)
.range(["white", "pink", "red"])
Insert cell
naturalbreaks3 = simple.ckmeans(popdensity, 5).map(v => v.pop())
Insert cell
threshldNB3 = d3.scaleThreshold()
.domain(naturalbreaks3)
.range(["white", "pink", "red"])
Insert cell
//map the id column to the values. Use this for joinging with topojson later
data = Object.assign(new Map(csv_data), {title: ["Population","PopulationDensity"]})
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