US Maps Including Alaska and Hawaii

Obtain United States map data frames of varying region types (e.g. county, state). The map data frames include Alaska and Hawaii conveniently placed to the bottom left, as they appear in most maps of the US. Convenience functions for plotting choropleths and working with FIPS codes are also provided.


CRAN Downloads Build Status codecov

See code to generate these images below

Purpose

Typically in R it is difficult to create nice US choropleths that include Alaska and Hawaii. The functions presented here attempt to elegantly solve this problem by manually moving these states to a new location and providing a fortified data frame for mapping and visualization. This allows the user to easily add data to color the map.

Shape Files

The shape files that we use to plot the maps in R are located in the data-raw folder. For more information refer to the US Census Bureau. Maps at both the state and county levels are included for convenience (zip code maps may be included in the future).

Installation

To install from CRAN (recommended), run the following code in an R console:

install.packages("usmap")

To install the package from this repository, run the following code in an R console:

# install.package("devtools")
devtools::install_github("pdil/usmap")

Installing using devtools::install_github will provide the most recent developer build of usmap.

To begin using usmap, simply import the package using the library command:

library(usmap)

To read the package vignettes, which explain helpful uses of the package, use vignette:

vignette(package = "usmap")
vignette("introduction", package = "usmap")
vignette("mapping", package = "usmap")

You can also read the vignettes online at the following links:

Features

  • Obtain map with certain region breakdown
state_map <- us_map(regions = "states")
county_map <- us_map(regions = "counties")
  • Include only certain states
new_england_states <- c("Connecticut", "Maine", "Massachusetts", "New Hampshire", "Rhode Island", "Vermont")
new_england_map <- us_map(regions = "states", include = new_england_states)
  • Look up FIPS codes for states and counties
fips("New Jersey")
#> "34"
 
fips("NJ", county = "Mercer")
#> "34021"
  • Retrieve states or counties with FIPS codes
fips_info(c("34", "35"))
#>         full abbr fips
#> 1 New Jersey   NJ   34 
#> 2 New Mexico   NM   35
 
fips_info(c("34021", "35021"))
#>         full abbr         county  fips
#> 1 New Jersey   NJ  Mercer County 34021
#> 2 New Mexico   NM Harding County 35021
  • Color map with data
plot_usmap(data = statepop, values = "pop_2015", lines = "red") + 
  scale_fill_continuous(name = "Population (2015)", label = scales::comma) + 
  theme(legend.position = "right")

Code for maps shown above

library(usmap)
library(ggplot2)
 
# States map
plot_usmap(data = statepop, values = "pop_2015") + 
  scale_fill_continuous(low = "white", high = "red", guide = FALSE) +
  scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))
 
# Counties map
plot_usmap(data = countypop, values = "pop_2015") + 
  scale_fill_continuous(low = "white", high = "red", guide = FALSE) +
  scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))

Acknowledgements

The code used to generate the map files was based on this blog post by Bob Rudis:
Moving The Earth (well, Alaska & Hawaii) With R

News

usmap 0.2.1

Improvements

  • Standardize documentation language.
  • Improve descriptiveness of error messages and warnings.

Bug Fixes

  • Allow data passed to map_with_data and plot_usmap to contain FIPS codes with missing leading zeros.
    • This usually occurs when the codes are read as numeric from a .csv file.

usmap 0.2.0

  • Add map_with_data function for adding user-defined data to map data.
  • Add ability to plot map with data automatically (utilizes new map_with_data function).

usmap 0.1.0

  • First release

Main features

  • Retrieve US map data frame for merging with data and plotting
  • Lookup FIPS codes for states and counties (reverse-lookup as well)
  • Map plotting convenience method (uses ggplot2)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("usmap")

0.2.1 by Paolo Di Lorenzo, 6 months ago


https://dilorenzo.pl/usmap


Report a bug at https://github.com/pdil/usmap/issues


Browse source code at https://github.com/cran/usmap


Authors: Paolo Di Lorenzo [aut, cre]


Documentation:   PDF Manual  


GPL-3 | file LICENSE license


Imports utils

Suggests ggplot2, knitr, proto, rmarkdown, scales, stringr, testthat


See at CRAN