diff --git a/2_process.R b/2_process.R index beae8a7cc28c9b38e89c2ebb3657a84b78978aef..a3247f4f315a64d1a6e76049f7802635a51cf228 100644 --- a/2_process.R +++ b/2_process.R @@ -163,5 +163,14 @@ tar_target(p2_census_acs5sub_household_data, states = p1_census_states, year = 2022, proj = p1_proj, survey_var = "acs5", percent_rename = FALSE), pattern = map(p2_census_acs5_household_layers), + iteration = "list"), +# Median Household Income in the Past 12 Months (in 2022 Inflation-Adjusted Dollars) for white only, Black or African American Alone, American Indian and Alaska Native Alone, Asian Alone, Native Hawaiian and Other Pacific Islander Alone, Hispanic or Latino +tar_target(p2_census_acs5_income_by_race_layers, + c("B19013A_001", "B19013B_001", "B19013C_001", "B19013D_001", "B19013E_001", "B19013I_001")), +tar_target(p2_census_acs5sub_income_by_race_data, + get_census_data(geography = 'county', variable = p2_census_acs5_income_by_race_layers, + states = p1_census_states, year = 2022, proj = p1_proj, + survey_var = "acs5", percent_rename = FALSE), + pattern = map(p2_census_acs5_income_by_race_layers), iteration = "list") ) \ No newline at end of file diff --git a/3_visualize.R b/3_visualize.R index 2de8bb6317fc8ca9e4830bb93995dd6443ccc728..7d2a1da3fc05dfbf4c6be2c4ef6fb57c971fe24e 100644 --- a/3_visualize.R +++ b/3_visualize.R @@ -1,6 +1,10 @@ source('3_visualize/src/plot_utils.R') + + # For case studies approach: select one demographic characteristic (hispanic/latino), p3_targets <- list( + +# desktop maps ------------------------------------------------------------ tar_target( p3_med_income_png, plot_census_map( @@ -139,8 +143,129 @@ p3_targets <- list( ), format = "file" ), - # Mobile maps - tar_target( + +# median income by race maps +tar_target( + p3_med_income_white_png, + plot_census_map( + census_data = p2_census_acs5sub_income_by_race_data[[1]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/med_income_census_white_2022.png", + leg_title = "Median Household Income in the Past 12 Months\n(in 2022 Inflation-Adjusted Dollars),\nWhite Householder", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$pal_positive, + width = p0_viz_config_df$width_desktop, + height = p0_viz_config_df$height_desktop, + font_size = p0_viz_config_df$font_size_desktop, + barwidth = 40, + barheight = 2 + ), + format = "file" +), + +tar_target( + p3_med_income_black_png, + plot_census_map( + census_data = p2_census_acs5sub_income_by_race_data[[2]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/med_income_census_black_2022.png", + leg_title = "Median Household Income in the Past 12 Months\n(in 2022 Inflation-Adjusted Dollars),\nBlack or African American Householder", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$pal_positive, + width = p0_viz_config_df$width_desktop, + height = p0_viz_config_df$height_desktop, + font_size = p0_viz_config_df$font_size_desktop, + barwidth = 40, + barheight = 2 + ), + format = "file" +), + +tar_target( + p3_med_income_american_indian_png, + plot_census_map( + census_data = p2_census_acs5sub_income_by_race_data[[3]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/med_income_census_american_indian_2022.png", + leg_title = "Median Household Income in the Past 12 Months\n(in 2022 Inflation-Adjusted Dollars),\nAmerican Indian and Alaska Native Householder", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$pal_positive, + width = p0_viz_config_df$width_desktop, + height = p0_viz_config_df$height_desktop, + font_size = p0_viz_config_df$font_size_desktop, + barwidth = 40, + barheight = 2 + ), + format = "file" +), + +tar_target( + p3_med_income_asian_png, + plot_census_map( + census_data = p2_census_acs5sub_income_by_race_data[[4]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/med_income_census_asian_2022.png", + leg_title = "Median Household Income in the Past 12 Months\n(in 2022 Inflation-Adjusted Dollars),\nAsian Householder", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$pal_positive, + width = p0_viz_config_df$width_desktop, + height = p0_viz_config_df$height_desktop, + font_size = p0_viz_config_df$font_size_desktop, + barwidth = 40, + barheight = 2 + ), + format = "file" +), + +tar_target( + p3_med_income_hawaiian_png, + plot_census_map( + census_data = p2_census_acs5sub_income_by_race_data[[5]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/med_income_census_hawaiian_2022.png", + leg_title = "Median Household Income in the Past 12 Months\n(in 2022 Inflation-Adjusted Dollars),\nNative Hawaiian and\n Other Pacific Islander Householder", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$pal_positive, + width = p0_viz_config_df$width_desktop, + height = p0_viz_config_df$height_desktop, + font_size = p0_viz_config_df$font_size_desktop, + barwidth = 40, + barheight = 2 + ), + format = "file" +), + +tar_target( + p3_med_income_hispanic_png, + plot_census_map( + census_data = p2_census_acs5sub_income_by_race_data[[6]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/med_income_census_hispanic_2022.png", + leg_title = "Median Household Income in the Past 12 Months\n(in 2022 Inflation-Adjusted Dollars),\nHispanic or Latino Householder", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$pal_positive, + width = p0_viz_config_df$width_desktop, + height = p0_viz_config_df$height_desktop, + font_size = p0_viz_config_df$font_size_desktop, + barwidth = 40, + barheight = 2 + ), + format = "file" +), +# mobile maps ------------------------------------------------------------- + tar_target( p3_med_income_mobile_png, plot_census_map( census_data = p2_perc_census_acs5_layers_sf[[2]], @@ -178,6 +303,9 @@ p3_targets <- list( ), format = "file" ), + +# mobile maps ------------------------------------------------------------- + tar_target( p3_tot_latino_mobile_png, diff --git a/3_visualize/src/plot_utils.R b/3_visualize/src/plot_utils.R index 03b7e2a2c461ebfa08edfe13ab7b016c66a8ecdd..fcbbfe435ba481ff0364ec0d4f61497c5f729cbc 100644 --- a/3_visualize/src/plot_utils.R +++ b/3_visualize/src/plot_utils.R @@ -50,7 +50,7 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, name = leg_title, limits = c(0, max(census_data[[var]], na.rm = TRUE)), labels = scales::comma, - na.value="white") + na.value="#F5F5F5") } else { census_map <- census_map + @@ -60,7 +60,7 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, name = leg_title, limits = c(0, 100), breaks = c(0, 25, 50, 75, 100), - na.value="white" + na.value="#F5F5F5" ) } ggsave(outfile_path, census_map, width = width, height = height, dpi = viz_config_df$dpi, bg = viz_config_df$bg_col, units = "in")