diff --git a/R/data.R b/R/data.R index cf3921d..b2d5445 100644 --- a/R/data.R +++ b/R/data.R @@ -990,24 +990,22 @@ #' @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 @@ -1015,8 +1013,8 @@ #' 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" @@ -1091,24 +1089,24 @@ #' @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 @@ -1116,7 +1114,7 @@ #' 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" diff --git a/man/xwalk_blockgroup2cca.Rd b/man/xwalk_blockgroup2cca.Rd index 1be74e8..3a4564b 100644 --- a/man/xwalk_blockgroup2cca.Rd +++ b/man/xwalk_blockgroup2cca.Rd @@ -78,24 +78,24 @@ If your data is only available at the tract level, you can use \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 @@ -103,7 +103,7 @@ 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() } diff --git a/man/xwalk_tract2cca.Rd b/man/xwalk_tract2cca.Rd index 1d29fca..2ec58de 100644 --- a/man/xwalk_tract2cca.Rd +++ b/man/xwalk_tract2cca.Rd @@ -77,24 +77,22 @@ allocation. \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 @@ -102,8 +100,8 @@ 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() } \keyword{datasets}