From 85f8d567ce76f221001c0ac9611fd93c02f8207e Mon Sep 17 00:00:00 2001 From: elmeraa <eazadpour@usgs.gov> Date: Tue, 28 May 2024 15:31:25 -0700 Subject: [PATCH] update map col pals and add disable map --- 3_visualize.R | 107 +++++++++++++++++++++++++++-------- 3_visualize/src/plot_utils.R | 12 ++-- 2 files changed, 87 insertions(+), 32 deletions(-) diff --git a/3_visualize.R b/3_visualize.R index 7d2a1da..a34ef04 100644 --- a/3_visualize.R +++ b/3_visualize.R @@ -15,7 +15,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/med_income_census_2022.png", leg_title = "Median household income, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -34,7 +34,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/perc_household_income_2022.png", leg_title = "Percent allocated household income\nin the past 12 months, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -54,7 +54,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/tot_latino_census_2022.png", leg_title = "Total Latino, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -74,7 +74,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/perc_latino_census_2022.png", leg_title = "Percent Latino, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -96,7 +96,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/tot_households_2022.png", leg_title = "Total households, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -115,7 +115,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/tot_female_households_2022.png", leg_title = "Total female households, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -134,7 +134,7 @@ p3_targets <- list( outfile_path = "3_visualize/out/median_rent_2022.png", leg_title = "Median gross rent, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_neg, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -155,7 +155,7 @@ tar_target( 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, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -175,7 +175,7 @@ tar_target( 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, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -195,7 +195,7 @@ tar_target( 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, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -215,7 +215,7 @@ tar_target( 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, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -235,7 +235,7 @@ tar_target( 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, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -255,7 +255,7 @@ tar_target( 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, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_desktop, height = p0_viz_config_df$height_desktop, font_size = p0_viz_config_df$font_size_desktop, @@ -264,6 +264,48 @@ tar_target( ), format = "file" ), + +# disability maps +tar_target( + p3_perc_disable_png, + plot_census_map( + census_data = p2_census_acs5sub_disability_data[[1]], + percent_leg = TRUE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/perc_disable_census_2022.png", + leg_title = "Percent disable, 2022", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, + 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_total_disable_png, + plot_census_map( + census_data = p2_census_acs5sub_disability_data[[2]], + percent_leg = FALSE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/tot_disable_census_2022.png", + leg_title = "Total disable, 2022", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, + 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, @@ -275,7 +317,7 @@ tar_target( outfile_path = "3_visualize/out/med_income_census_2022_mobile.png", leg_title = "Median household income, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -294,7 +336,7 @@ tar_target( outfile_path = "3_visualize/out/perc_household_income_2022_mobile.png", leg_title = "Percent allocated household income\nin the past 12 months, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -303,10 +345,6 @@ tar_target( ), format = "file" ), - -# mobile maps ------------------------------------------------------------- - - tar_target( p3_tot_latino_mobile_png, plot_census_map( @@ -317,7 +355,7 @@ tar_target( outfile_path = "3_visualize/out/tot_latino_census_2022_mobile.png", leg_title = "Total Latino, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -337,7 +375,7 @@ tar_target( outfile_path = "3_visualize/out/perc_latino_census_2022_mobile.png", leg_title = "Percent Latino, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -356,7 +394,7 @@ tar_target( outfile_path = "3_visualize/out/tot_households_2022_mobile.png", leg_title = "Total households, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -375,7 +413,7 @@ tar_target( outfile_path = "3_visualize/out/tot_female_households_2022_mobile.png", leg_title = "Total female households, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_positive, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -394,7 +432,7 @@ tar_target( outfile_path = "3_visualize/out/median_rent_2022_mobile.png", leg_title = "Median gross rent, 2022", viz_config_df = p0_viz_config_df, - viz_config_pal = p0_viz_config_pal$pal_neg, + viz_config_pal = p0_viz_config_pal$socioeconomic_status, width = p0_viz_config_df$width_mobile, height = p0_viz_config_df$height_mobile, font_size = p0_viz_config_df$font_size_mobile, @@ -402,5 +440,24 @@ tar_target( barheight = 3 ), format = "file" - ) + ), +tar_target( + p3_disable_mobile_png, + plot_census_map( + census_data = p2_census_acs5sub_disability_data[[1]], + percent_leg = TRUE, + var = 'estimate', + conus_sf = p1_conus_sf, + outfile_path = "3_visualize/out/perc_disable_2022_mobile.png", + leg_title = "Total disable, 2022", + viz_config_df = p0_viz_config_df, + viz_config_pal = p0_viz_config_pal$demographic_characteristics, + width = p0_viz_config_df$width_mobile, + height = p0_viz_config_df$height_mobile, + font_size = p0_viz_config_df$font_size_mobile, + barwidth = 40, + barheight = 3 + ), + format = "file" +) ) \ No newline at end of file diff --git a/3_visualize/src/plot_utils.R b/3_visualize/src/plot_utils.R index fcbbfe4..75fb344 100644 --- a/3_visualize/src/plot_utils.R +++ b/3_visualize/src/plot_utils.R @@ -27,7 +27,7 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, geom_sf(data = conus_sf, fill = NA, color = viz_config_df$conus_outline_col, - linewidth = 0.2, + linewidth = 0.5, linetype = "solid") + theme_void() + theme(text = element_text(family = viz_config_df$font_legend, size = font_size), @@ -44,9 +44,8 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, if (percent_leg == FALSE) { census_map <- census_map + - scale_fill_distiller( - palette = viz_config_pal, - direction = 1, + scale_fill_gradientn( + colors = colorRampPalette(c("#F8F9FF", viz_config_pal))(100), name = leg_title, limits = c(0, max(census_data[[var]], na.rm = TRUE)), labels = scales::comma, @@ -54,9 +53,8 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, } else { census_map <- census_map + - scale_fill_distiller( - palette = viz_config_pal, - direction = 1, + scale_fill_gradientn( + colors = colorRampPalette(c("#F8F9FF", viz_config_pal))(100), name = leg_title, limits = c(0, 100), breaks = c(0, 25, 50, 75, 100), -- GitLab