rud.is

U.S. Albers composite with Alaska & Hawaii, longlat projection (so you can use it as you see fit).

I have no idea why I haven’t done this before. I’ll make one for counties as well and put them both into ggalt for the next CRAN submission. I might even include territories, too.

Original GeoJSON is from here.

library(sp)
library(rgeos)
library(rgdal)
library(maptools)
library(ggplot2)
library(ggalt)
library(ggthemes)

In case it’s not obvious, this URL is where the file is at. Here’s a right-clickable link.

URL <- "http://rud.is/dl/albers_composite_us_states.geojson"
fil <- basename(URL)
if (!file.exists(fil)) download.file(URL, fil, quiet=TRUE)

us <- readOGR("albers_composite_us_states.geojson", "OGRGeoJSON", 
              stringsAsFactors=FALSE, verbose=FALSE)

see what we’ve got:

plot(us)

don’t forget the data!

(dplyr::glimpse(us@data))
## Observations: 51
## Variables: 5
## $ GEO_ID     (chr) "0400000US04", "0400000US05", "0400000US06", "04000...
## $ STATE      (chr) "04", "05", "06", "08", "09", "11", "13", "17", "18...
## $ NAME       (chr) "Arizona", "Arkansas", "California", "Colorado", "C...
## $ LSAD       (chr) "", "", "", "", "", "", "", "", "", "", "", "", "",...
## $ CENSUSAREA (dbl) 113594.084, 52035.477, 155779.220, 103641.888, 4842...
## NULL

ugh. we can do better! let’s define some projections for use later

albers <- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
longlat <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

now to make it prettier in base

us <- spTransform(us, CRS(albers))
plot(us)

yay! now to make it more usable in ggplot2

us <- spTransform(us, CRS(longlat))

with plain ol’ ggplot

us_map <- fortify(us, region="NAME")

gg <- ggplot()
gg <- gg + geom_map(data=us_map, map=us_map,
                    aes(x=long, y=lat, map_id=id),
                    color="#2b2b2b", size=0.1, fill=NA)
gg <- gg + theme_map()

ugh.

gg + coord_map()

yay!

gg + coord_map("polyconic")

even better

gg + coord_proj(albers)