Published
Edited
Apr 23, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
labels = ["low", "", "high"]
Insert cell
n = Math.floor(Math.sqrt(colors.length))
Insert cell
x = d3.scaleQuantile(Array.from(data.values(), d => d[0]), d3.range(n))
Insert cell
y = d3.scaleQuantile(Array.from(data.values(), d => d[1]), d3.range(n))
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
Insert cell
//Rotate the map sets the longitude of origin for our UTM projection.
projection = d3.geoTransverseMercator().rotate([87,0]).fitExtent([[10, 10], [width, height]], polygon_features);
Insert cell
polygon_features = topojson.feature(polygons, polygons.objects.FINALMTMAP)
Insert cell
Insert cell
data = Object.assign(new Map(d3.csvParse(await FileAttachment("MTFoodAccessFINAL (1).csv").text(), ({GEOID, MedianFamilyIncome, TractKids, TractSeniors, POP2010}) => [GEOID, [+MedianFamilyIncome, (TractKids+TractSeniors)/100]])), {title: ["Median Income ", "% of Dependents"]})
Insert cell
idAttribute = "GEOID"
Insert cell
Insert cell
polygons = FileAttachment("FINALMTMAP (1).json").json()
Insert cell
height = 610
Insert cell
width = 875
Insert cell
Insert cell
Insert cell
color = {
return value => {
if (!value) return "#ccc";
let [a, b] = value;
return colors[y(b) + x(a) * n];
};
}
Insert cell
formatNum = d3.format(".1f")
Insert cell
format = (value) => {
if (!value) return "N/A";
let [a, b] = value;
return `${a} ${data.title[0]}${labels[x(a)] && ` (${labels[x(a)]})`}
${formatNum(b)} ${data.title[1]}${labels[y(b)] && ` (${labels[y(b)]})`}`;
}
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
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