Source: American Community Survey, 2011 5-Year Estimate
This map was inspired by a similar map found on Wikipedia. I wasn’t wild about the diverging color scale, so I thought it would be a fun challenge to recreate.
Finding the shapefiles was easy; I used the U.S. National Atlas 1:1,000,000 scale dataset, conveniently packaged in my U.S. Atlas repository. I reprojected the shapefiles to the California Albers projection using ogr2ogr:
ogr2ogr \
-f 'ESRI Shapefile' \
-t_srs 'EPSG:3310' \
tracts.shp \
shp/ca/tracts.shp
I used both the census tracts and the county shapefiles, since drawing county boundaries makes the geography more familiar.
Getting the population density per census tract was harder. I knew the data was available as part of the Census Bureau’s American Community Survey, but the American FactFinder is quite onerous. It takes almost twenty steps to find and download the data!
- Go to factfinder2.census.gov.
- Find where it says “American Community Survey” and click “get data »”.
- Click the blue “Geographies” button on the left.
- In the pop-up, select census tract in the “geographic type” menu.
- Select California in the resulting “state” menu.
- Click “All Census Tracts within California”.
- Click the “ADD TO YOUR SELECTIONS” button.
- Click “CLOSE” to dismiss the pop-up.
- Click the blue “Topics” button on the left.
- In the pop-up, expand the “People” submenu.
- Expand the “Basic Count/Estimate” submenu.
- Click “Population Total”.
- Click “CLOSE” to dismiss the pop-up.
- In the table, click on the most recent ACS 5-year estimate named “TOTAL POPULATION”.
- On the next page, click the “Download” link under “Actions”.
- In the pop-up, click “OK”.
- Wait for it to “build” your file.
- When it’s ready, click “DOWNLOAD”.
- Finally, expand the downloaded zip file (ACS_11_5YR_B01003.zip).
I mean, does that seem like too many steps to anyone else? How about a simple URL where I can substitute a year and a state FIPS code and just download the data directly without fighting through ridiculous wizards? Anyway, assuming you didn’t die of old age while folllowing those instructions, you should now have a ACS_11_5YR_B01003_with_ann.csv file which has the data.
Lastly, all we have to do is join the population data with the shapefile using topojson -e
. (See the TopoJSON command-line reference for full details.)
topojson
-e ACS_11_5YR_B01003_with_ann.csv \
--id-property GEOID,GEO.id2 \
-p population=+HD01_VD01,area=+ALAND \
-s 1 \
--width 960 \
--margin 10 \
-o ca.json \
-- tracts.shp counties.shp
The resulting TopoJSON file has the 2011 estimated population of each census tract as the population
property, and the land area in square meters as the area
property. Dividing one by the other and converting to square miles, we get the desired map!