By hrbrmstr
Folks who’ve been tracking this blog on R-bloggers probably remember this post where I showed how to create a composite U.S. map with an Albers projection (which is commonly referred to as AlbersUSA these days thanks to D3).
I’m not sure why I didn’t think of this earlier, but you don’t need to do those geographical machinations every time you want a prettier & more inclusive map (Alaska & Hawaii have been states for a while, so perhaps we should make more of an effort to include them in both data sets and maps). After doing the map transformations, the composite shape can be saved out to a shapefile, preferably GeoJSON since (a) you can use geojsonio::geojson_write()
to save it and (b) it’s a single file vs a ZIP/directory.
I did just that and saved both state and country maps out with FIPS codes and other useful data slot bits and created a small data package : albersusa
: with some helper functions. It’s not in CRAN yet so you need to devtools::install_github("hrbrmstr/albersusa")
to use it. The github repo has some basic examples, heres a slightly more complex one.
Mapping Obesity
I grabbed an obesity data set from the CDC and put together a compact example for how to make a composite U.S. county choropleth to show obesity rates per county (for 2012, which is the most recent data). I read in the Excel file, pull out the county FIPS code and 2012 obesity rate, then build the choropleth. It’s not a whole lot of code, but that’s one main reason for the package!
library(readxl) |