Public
Edited
Apr 26, 2023
Insert cell
md`# Grocery Store Access in Rock County`
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
rockcounty = FileAttachment("rockcountymap.json").json()
Insert cell
rockcounty_features = topojson.feature(rockcounty, rockcounty.objects.rockcountymap)
Insert cell
csv_data = d3.csvParse(await FileAttachment("rockcountydata@3.csv").text(),({GEOID, Pop2010, lalowi1}) => [GEOID, +lalowi1/+Pop2010, [+Pop2010, +lalowi1, +lalowi1/+Pop2010]])
Insert cell
csv_data_objects = Object.assign((d3.csvParse(await FileAttachment("rockcountydata@3.csv").text(), d3.autoType)).map(({GEOID, Pop2010, lalowi1}) => ({GEOID: +GEOID, pctInterst: +lalowi1/+Pop2010})))
Insert cell
GEOID = Array.from(csv_data.values(), d => d[0])
Insert cell
//this is how to take the values of a variable (column) from all variables you created from the csv file
Pop2010 = Array.from(csv_data.values(), d => d[2][0])
Insert cell
Insert cell
lalowi1 = Array.from(csv_data.values(), d => d[2][1]).filter(d => d >0)
Insert cell
Insert cell
Proportion_access = Array.from(csv_data.values(), d => d[1]).filter(d => d >0)
Insert cell
Insert cell
d3.min(Proportion_access)
Insert cell
//this is how you map the id column to the values. We will use this for joining with topojson later.
data = Object.assign(new Map(csv_data), {title: ["Proportion of People With Easy Access to Supermarket"]})
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
Insert cell
Insert cell
Insert cell
xproportionalSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.rockcountymap))
.attr("fill", "darkgrey")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.rockcountymap, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "darkblue")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
const legend = svg.append("g")
.attr("fill", "darkgrey")
.attr("transform", "translate(50,450)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([0.000365764447695684, d3.max([...data.values()])])
.join("g");
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "darkgrey")
.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", "darkblue")
.attr("fill-opacity", 0.5)
.attr("stroke", "lightblue")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(points.features
.map(d => (d.value = data.get(d.properties.GEOID), 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.GEOID)))
.append("title")
.text(d => `${d.properties.GEOID} : ${format(d.value)}`);
return svg.node();
}
Insert cell
Insert cell
height = 600
Insert cell
width = 600
Insert cell
Insert cell
path_points = d3.geoPath().projection(projection)
Insert cell
path_basemap = d3.geoPath().projection(projection)
Insert cell
projection = d3.geoTransverseMercator().rotate([90,0]).fitExtent([[80, 80], [width, height]], rockcounty_features);
Insert cell
Insert cell
format = d3.format(".2s")
Insert cell
Insert cell
radius(0.5986622073578596)
Insert cell
d3.max([...data.values()])
Insert cell
radius(0.000365764447695684)
Insert cell
//proportional symbols
radius = d3.scaleSqrt([0, d3.max([...data.values()])], [3, 20])
Insert cell
Insert cell
data.get("55105000100")
Insert cell
Insert cell
points = FileAttachment("rockcountymap2_centroids.geojson").json()
Insert cell
basepolygons = FileAttachment("rockcountymap.json").json()
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