For the 48-state plus District of Columbia case and saved functions and objects used here, see the walkthrough installment.

Load the required libraries, functions and data objects

x = c("ggplot2", "rgdal", "maptools", "mapproj", "rgeos")
lapply(x, library, character.only = TRUE)
## [[1]]
## [1] "ggplot2"   "stats"     "graphics"  "grDevices" "utils"     "datasets" 
## [7] "methods"   "base"     
## 
## [[2]]
##  [1] "rgdal"     "sp"        "ggplot2"   "stats"     "graphics" 
##  [6] "grDevices" "utils"     "datasets"  "methods"   "base"     
## 
## [[3]]
##  [1] "maptools"  "rgdal"     "sp"        "ggplot2"   "stats"    
##  [6] "graphics"  "grDevices" "utils"     "datasets"  "methods"  
## [11] "base"     
## 
## [[4]]
##  [1] "mapproj"   "maps"      "maptools"  "rgdal"     "sp"       
##  [6] "ggplot2"   "stats"     "graphics"  "grDevices" "utils"    
## [11] "datasets"  "methods"   "base"     
## 
## [[5]]
##  [1] "rgeos"     "mapproj"   "maps"      "maptools"  "rgdal"    
##  [6] "sp"        "ggplot2"   "stats"     "graphics"  "grDevices"
## [11] "utils"     "datasets"  "methods"   "base"

Functions

remove.territories = function(.df) {
    subset(.df, 
        .df$id != "AS" &
        .df$id != "MP" &
        .df$id != "GU" & 
        .df$id != "PR" &
        .df$id != "VI" 
    )
}
#save("remove.territories", file = "helpers/remove.territories")

Convenience definitions

plain_theme = theme(axis.text=element_blank()) + 
    theme(panel.background = element_blank(), 
        panel.grid = element_blank(), 
        axis.ticks = element_blank())

no_ylab = ylab("") 
no_xlab = xlab("")

Load the basemap

setwd("~/Desktop/gitmo/playpen/r")
load("data/cb5")
us = cb5

Transform geographical coordinates to Lambert Azimuth Equal Area projection

us_aea = spTransform(us, CRS("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"))
us_aea@data$id = rownames(us_aea@data)

Move Alaska (scaled down) and Hawaii

alaska = us_aea[us_aea$STATEFP=="02",]
alaska = elide(alaska, rotate=-50)
alaska = elide(alaska, scale=max(apply(bbox(alaska), 1, diff)) / 2.3)
alaska = elide(alaska, shift=c(-2100000, -2500000))
proj4string(alaska) = proj4string(us_aea)

hawaii = us_aea[us_aea$STATEFP=="15",]
hawaii = elide(hawaii, rotate=-35)
hawaii = elide(hawaii, shift=c(5400000, -1400000))
proj4string(hawaii) = proj4string(us_aea)

Remove Alaska and Hawaii from base map and substitute transformed versions

us_aea = us_aea[!us_aea$STATEFP %in% c("02", "15"),]
us_aea = rbind(us_aea, alaska, hawaii)

Prepare a data frame for plotting and optionally save

us50 <- fortify(us_aea, region="STUSPS")
us50 = remove.territories(us50)
#save('helpers/us50')

Plot the map

p = ggplot(data=us50) + 
    geom_map(map=us50, aes(x=long, y=lat, map_id=id, group=group), ,fill="white", color="dark grey", size=0.15) + 
    no_ylab + 
    no_xlab + 
    plain_theme
p

Next up

Moving and enlarging Delaware, the District of Columbia and Rhode Island.

Disclaimer

I am unable to answer questions relating to the use of this code under Windows.

Credits

Algorithms

Scale and shift

Data

See sources in the walkthrough installment.

R Packages

  • Roger Bivand and Nicholas Lewin-Koh (2015). maptools: Tools for Reading and Handling Spatial Objects. R package version 0.8-36. http://CRAN.R-project.org/package=maptools
  • Roger Bivand and Colin Rundel (2015). rgeos: Interface to Geometry Engine - Open Source (GEOS). R package version 0.3-11. http://CRAN.R-project.org/package=rgeos
  • Roger Bivand, Tim Keitt and Barry Rowlingson (2015). rgdal: Bindings for the Geospatial Data Abstraction Library. R package version 1.0-4 rgdal
  • Doug McIlroy. Packaged for R by Ray Brownrigg, Thomas P Minka and transition to Plan 9 codebase by Roger Bivand. (2015). mapproj: Map Projections. R package version 1.2-3. http://CRAN.R-project.org/package=mappro
  • Erich Neuwirth (2014). RColorBrewer: ColorBrewer Palettes. R package version 1.1-2. RColorBrewer
  • R Core Team (2015). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. [grid]
  • H. Wickham. ggplot2: elegant graphics for data analysis. Springer New York, 2009. ggplot2

License

Copyright (c) 2015, Richard Careaga

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.