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.


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

estout <- get_acs(geography = "state",
                  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)

#> # 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)) +

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

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.