Public
Edited
Mar 27, 2023
1 fork
Insert cell
md`# GEOG VIS Assignment 4`
Insert cell
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
newJerseyPoints = FileAttachment("newJerseyCentroids.geojson").json()
Insert cell
basepolygons = FileAttachment("NJCounties.json").json()
Insert cell
basefeatures = topojson.feature(basepolygons, basepolygons.objects.NJCounties)
Insert cell
newJersey_csv = d3.csvParse(await FileAttachment("County_Boundaries_of_NJ (1).csv").text(),({POP2010, SQ_MILES, COUNTY}) => [COUNTY, POP2010/SQ_MILES])
Insert cell
data = Object.assign(new Map(newJersey_csv))
Insert cell
njPopDensity = Array.from(newJersey_csv.values(), d => d[1])
Insert cell
radius = d3.scaleSqrt([d3.min([...data.values()]), d3.max([...data.values()])], [0, 20])
Insert cell
d3.max([...data.values()])
Insert cell
format = d3.format(".2s")
Insert cell
projection = d3.geoTransverseMercator().rotate([122,0]).fitExtent([[80, 80], [width, height]], basefeatures);
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
height = 610
Insert cell
width = 900
Insert cell
proportionalSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.NJCounties))
.attr("fill", "#ccc")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.NJCounties, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(150,450)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([d3.min([...data.values()]), d3.max([...data.values()])])
.join("g");
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("cy", d => -radius(d))
.attr("r", radius);
legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(format);
svg.append("g")
.attr("fill", "#7a0177")
.attr("fill-opacity", 0.5)
.attr("stroke", "#f768a1")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(newJerseyPoints.features
.map(d => (d.value = data.get(d.properties.COUNTY), d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path_points.centroid(d)})`)
.attr("r", d => radius(data.get(d.properties.COUNTY)))
.append("title")
.text(d => `${d.properties.COUNTY} : ${format(d.value)}`);
return svg.node();
}
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