Skip to content

Commit

Permalink
Update CCA xwalk examples with 2020 census data
Browse files Browse the repository at this point in the history
  • Loading branch information
nmpeterson committed Feb 23, 2022
1 parent ac67009 commit c433d9a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 60 deletions.
58 changes: 28 additions & 30 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -990,33 +990,31 @@
#' @examples
#' suppressPackageStartupMessages(library(dplyr))
#'
#' # View the tracts with population not fully contained in a single CCA
#' # View the tracts with population split between multiple CCAs
#' filter(xwalk_tract2cca, pop_pct < 1)
#'
#' # Estimate CCA-level transit mode share from tract-level ACS data
#' df_tract <- tidycensus::get_acs(
#' "tract", state = "IL", county = "031", table = "B08006",
#' year = 2019, survey = "acs5", output = "wide", cache_table = TRUE
#' # Estimate CCA-level population density from tract-level Census data
#' df_tract <- tidycensus::get_decennial(
#' geography = "tract", variables = c("P1_001N"),
#' year = 2020, state = "IL", county = c("031", "043"), output = "wide"
#' ) %>%
#' rename(workers = B08006_001E, transit = B08006_008E) %>%
#' select(GEOID, workers, transit)
#' suppressMessages() %>% # Hide tidycensus messages
#' select(geoid_tract = GEOID, pop = P1_001N)
#'
#' df_cca <- xwalk_tract2cca_2010 %>% # Note use of 2010 version with 2019 ACS
#' left_join(df_tract, by = c("geoid_tract" = "GEOID")) %>%
#' mutate(transit = transit * pop_pct,
#' workers = workers * pop_pct) %>%
#' df_cca <- xwalk_tract2cca %>%
#' left_join(df_tract, by = "geoid_tract") %>%
#' mutate(pop = pop * pop_pct) %>%
#' group_by(cca_num) %>%
#' summarize_at(vars(transit, workers), sum) %>%
#' mutate(transit_commute_pct = transit / workers)
#' summarize(pop = sum(pop))
#' df_cca
#'
#' # Join to cca_sf for mapping
#' library(ggplot2)
#' cca_sf %>%
#' left_join(df_cca, by = "cca_num") %>%
#' ggplot() +
#' geom_sf(aes(fill = transit_commute_pct), lwd = 0.1) +
#' scale_fill_viridis_c() +
#' geom_sf(aes(fill = pop / sqmi), lwd = 0.1) +
#' scale_fill_viridis_c(direction = -1) +
#' theme_void()
"xwalk_tract2cca"

Expand Down Expand Up @@ -1091,32 +1089,32 @@
#' @examples
#' suppressPackageStartupMessages(library(dplyr))
#'
#' # View the block groups with households not fully contained in a single CCA
#' filter(xwalk_blockgroup2cca, hh_pct < 1)
#' # View the block groups with housing units split between multiple CCAs
#' filter(xwalk_blockgroup2cca, hu_pct < 1)
#'
#' # Estimate CCA-level unemployment rate from block group-level ACS data
#' df_blkgrp <- tidycensus::get_acs(
#' "block group", state = "IL", county = "031", table = "B23025",
#' year = 2019, survey = "acs5", output = "wide", cache_table = TRUE
#' # Estimate CCA-level housing vacancy rates from block group-level Census data
#' df_blkgrp <- tidycensus::get_decennial(
#' geography = "block group", variables = c("H1_001N", "H1_003N"),
#' year = 2020, state = "IL", county = c("031", "043"), output = "wide"
#' ) %>%
#' rename(civ_lf = B23025_003E, unemp = B23025_005E) %>%
#' select(GEOID, civ_lf, unemp)
#' suppressMessages() %>% # Hide tidycensus messages
#' select(geoid_blkgrp = GEOID, hu_tot = H1_001N, hu_vac = H1_003N)
#'
#' df_cca <- xwalk_blockgroup2cca_2010 %>% # Note use of 2010 version with 2019 ACS
#' left_join(df_blkgrp, by = c("geoid_blkgrp" = "GEOID")) %>%
#' mutate(civ_lf = civ_lf * pop_pct,
#' unemp = unemp * pop_pct) %>%
#' df_cca <- xwalk_blockgroup2cca %>%
#' left_join(df_blkgrp, by = "geoid_blkgrp") %>%
#' mutate(hu_tot = hu_tot * hu_pct,
#' hu_vac = hu_vac * hu_pct) %>%
#' group_by(cca_num) %>%
#' summarize_at(vars(civ_lf, unemp), sum) %>%
#' mutate(unemp_rate = unemp / civ_lf)
#' summarize_at(vars(hu_tot, hu_vac), sum) %>%
#' mutate(vac_rate = hu_vac / hu_tot)
#' df_cca
#'
#' # Join to cca_sf for mapping
#' library(ggplot2)
#' cca_sf %>%
#' left_join(df_cca, by = "cca_num") %>%
#' ggplot() +
#' geom_sf(aes(fill = unemp_rate), lwd = 0.1) +
#' geom_sf(aes(fill = vac_rate), lwd = 0.1) +
#' scale_fill_viridis_c(direction = -1) +
#' theme_void()
"xwalk_blockgroup2cca"
Expand Down
30 changes: 15 additions & 15 deletions man/xwalk_blockgroup2cca.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions man/xwalk_tract2cca.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c433d9a

Please sign in to comment.