tidycensus: shift_geo = TRUE

When running get_acs(), is it possible to set shift_geo = TRUE (or create a similar looking result) if you are not using data from the whole US? I want to include Alaska and Hawaii in a map using get_acs data while only using the data for certain states and not the whole US

Please help!

You can subset after getting the data for all states. See example below for the west coast along with HI and AK.

library(tidyverse)
library(tidycensus)

statelist <- c("AK", "HI", "CA", "WA", "OR")

estout <- get_acs(geography = "state",
                  variables="B01001_001",
                  year=2019,
                  survey="acs1",
                  geometry = TRUE,
                  shift_geo = TRUE)
#> Getting data from the 2019 1-year ACS
#> The one-year ACS provides data for geographies with populations of 65,000 and greater.
#> Using feature geometry obtained from the albersusa package
#> Please note: Alaska and Hawaii are being shifted and are not to scale.


fipslist <- fips_codes %>%
  as_tibble() %>%
  select(state, state_code) %>%
  group_by(state, state_code) %>%
  slice(1) %>%
  ungroup() %>%
  filter(state %in% statelist)

fipslist
#> # A tibble: 5 x 2
#>   state state_code
#>   <chr> <chr>     
#> 1 AK    02        
#> 2 CA    06        
#> 3 HI    15        
#> 4 OR    41        
#> 5 WA    53

estsub <- estout %>%
  filter(GEOID %in% c(fipslist$state_code))

estsub %>%
  ggplot(aes(fill=estimate)) +
  geom_sf()

Created on 2021-01-07 by the reprex package (v0.3.0)

1 Like