Published
Edited
Apr 12, 2020
1 fork
1 star
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
Insert cell
Insert cell
color = {
return value => {
if (!value) return "#ccc";
let [a, b] = value;
return colors[y(b) + x(a) * n];
};
}
Insert cell
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
//Rotate the map sets the longitude of origin for our UTM projection.
projection = d3.geoTransverseMercator()
.rotate([93, 0])
.center([0, 62])
.fitExtent([[80, 80], [width, height]], polygon_features);
Insert cell
height = 550
Insert cell
width = 875
Insert cell
Insert cell
idAttribute = "NAME"
Insert cell
data = Object.assign(new Map(d3.csvParse(await FileAttachment("Louisiana.csv").text(), ({NAME, BLACK, FHH_CHILD, POP2010}) => [NAME, [+FHH_CHILD, 100 * +BLACK/+POP2010]])), {title: ["Single Mother Households", "% Black"]})
Insert cell
polygon_features = topojson.feature(polygons, polygons.objects.LouisianaGEO)
Insert cell
polygons = FileAttachment("LouisianaTOPO.json").json()
Insert cell
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