shift_geometry: Shift and rescale Alaska, Hawaii, and Puerto Rico in a...

View source: R/shift_geometry.R

shift_geometryR Documentation

Shift and rescale Alaska, Hawaii, and Puerto Rico in a US-wide sf object


This function will shift and optionally rescale a US dataset for thematic mapping of Alaska, Hawaii, and Puerto Rico with respect to the continental United States. Features in the continental United States will have their CRS transformed to USA Contiguous Albers Equal Area Conic ('ESRI:102003'). Alaska, Hawaii, and Puerto Rico features are transformed to appropriate coordinate systems for those areas, then shifted and optionally re-scaled before being assigned the 'ESRI:102003' CRS. Options for users include preserve_area which allows for preservation of the area of AK/HI/PR relative to the continental US if desired, and two possible arrangements which are specified with position = "below" or position = "outside"


  geoid_column = NULL,
  preserve_area = FALSE,
  position = c("below", "outside")



The input sf dataset


The GEOID column of the dataset that contains a state ID. If used, will speed up processing and avoid spatial overlay to infer locations. Defaults to NULL.


If TRUE, the areas of Alaska/Hawaii/Puerto Rico relative to the continental US will be preserved. Defaults to FALSE where Alaska is proportionally smaller and Hawaii/Puerto Rico are proportionally larger.


One of "below" (the default) or "outside". If "below", Alaska, Hawaii, and Puerto Rico will be placed below the continental United States. If "outside", features will be moved outside the continental US; Alaska will be northwest of Washington, Hawaii southwest of California, and Puerto Rico southeast of Florida.


shift_geometry(), while designed for use with objects from the tigris package, will work with any US dataset. If aligning datasets from multiple sources, you must take care to ensure that your options specified in preserve_area and position are identical across layers. Otherwise your layers will not align correctly.

The function is also designed to work exclusively with features in the continental United States, Alaska, Hawaii, and Puerto Rico. If your dataset includes features outside these areas (e.g. other US territories or other countries), you may get unworkable results. It is advisable to filter out those features before using shift_geometry().

Work on this function is inspired by and adapts some code from Claus Wilke's book Fundamentals of Data Visualization (; Bob Rudis's albersusa R package (; and the ggcart R package (


The input sf object with transformed geometry


## Not run: 

# Shift and rescale AK/HI/PR for thematic mapping

us_states <- states(cb = TRUE, resolution = "20m") %>%

# Shift but preserve area
us_states_eqarea <- states(cb = TRUE, resolution = "20m") %>%
  shift_geometry(preserve_area = TRUE)

# Shift and rescale but position AK/HI/PR outside the continental US rather than below
us_states_outside <- states(cb = TRUE, resolution = "20m") %>%
  shift_geometry(position = "outside")

# Shift a dataset obtained outside tigris and make a map
income_by_metro <- get_acs(
  geography = "cbsa",
  variables = "B01002_001",
  geometry = TRUE
) %>%

ggplot() +
  geom_sf(data = income_by_metro, aes(fill = estimate), color = NA) +
  geom_sf(data = us_states, fill = NA, color = "black", size = 0.1) +
  scale_fill_viridis_c() +
  theme_void(base_size = 16) +
  labs(title = "Median age by CBSA, 2015-2019 ACS",
       fill = "ACS estimate  ",
       caption = "Note: Alaska, Hawaii, and Puerto Rico are shifted and not to scale.") +
  theme(plot.title = element_text(hjust = 0.5))

## End(Not run)

tigris documentation built on June 4, 2022, 1:06 a.m.