Published
Edited
Dec 2, 2020
1 fork
Importers
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sorted = countiesGeoArea
.map(d => d.properties)
.sort((a, b) => b.pop_density - a.pop_density)
Insert cell
countyPopDensityByFips = new Map(
countiesGeoArea.map(({ id, properties }) => [id, properties])
)
Insert cell
countyPopDensityFC = ({
type: "FeatureCollection",
features: countiesGeoArea.slice()
})
Insert cell
countiesGeoArea = countiesGeo.features
.map(f => {
const area_sqkm = landAreaByFips.get(f.id).area / 1000000;
const pop = countiesPopulation.get(f.id);
const pop_density = pop && area_sqkm ? pop / area_sqkm : undefined;

return {
...f,
properties: {
...f.properties,
pop,
area_sqkm,
pop_density
}
};
})
.filter(d => d.properties.pop_density !== undefined)
Insert cell
landAreaByFips = new Map(
usCountyArea.map(({ GEOID, NAME, ALAND }) => [
GEOID,
{ name: NAME, area: ALAND }
])
)
Insert cell
countiesGeo = topojson.feature(us, us.objects.counties)
Insert cell
Insert cell
Insert cell
usCountyArea = {
const csv = await FileAttachment("us_county_land_area.csv").csv();
for (let row of csv) {
row.ALAND = Number(row.ALAND);
}
return csv;
}
Insert cell
Insert cell
countiesPopulation = {
const data = await d3.json(
`${baseURI}?get=B01001_001E&for=county:*&in=state:*&key=${key}`
);

return new Map(
data.slice(1).map(([value, state, county]) => [`${state}${county}`, +value])
);
}
Insert cell
Insert cell
us = FileAttachment("counties-10m.json").json()
Insert cell
Insert cell
import {
map,
mapLegend
} from "@clhenrick/u-s-county-population-density-choropleth"
Insert cell
import { baseURI, key } from "@clhenrick/us-census-constants"
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3-fetch@2")
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