diff --git a/2_process.R b/2_process.R index 30de35d1831b82131e45f0d60ecb8cc0c8b4bf64..6262a313fc9d1dea805e8c77ee6542ca0f4d8617 100644 --- a/2_process.R +++ b/2_process.R @@ -170,6 +170,26 @@ tar_target(p2_census_acs5sub_household_data, survey_var = "acs5", percent_rename = FALSE), pattern = map(p2_census_acs5_household_layers), iteration = "list"), +# percent households variable +# DP04_0002P = Percent!!HOUSING OCCUPANCY!!Total housing units!!Occupied housing units +# this does not have geometry, so we will join using tigris::counties() +tar_target(p2_census_acs5profile_household_layers, + c("DP04_0002P")), +tar_target(p2_census_acs5profile_household_data, + get_acs(geography = "county", + variables = p2_census_acs5profile_household_layers, + year = 2022, + survey = "acs5") |> + mutate(state_name = sub(".*, ", "", NAME)) |> + filter(state_name %in% p1_census_states)), +tar_target(p2_counties_sf, + tigris::counties() |> + st_transform(crs = p1_proj) |> + ms_simplify(keep = 0.2)), +# Join counties spatial to households dataframe +tar_target(p2_census_acs5profile_household_sf, + p2_counties_sf |> + inner_join(p2_census_acs5profile_household_data, by = "GEOID")), # 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")), diff --git a/3_visualize.R b/3_visualize.R index 9b1e1b96c9513d2860633e14d928c43b7b53ac10..75eaac1d3c2e129e61f533603e6ff9cabdd4a586 100644 --- a/3_visualize.R +++ b/3_visualize.R @@ -24,45 +24,45 @@ p3_targets <- list( ), format = "file" ), - tar_target( - p3_perc_household_income_png, - plot_census_map( - census_data = p2_census_acs5sub_income_data[[1]], - percent_leg = TRUE, - var = 'percent', - conus_sf = p1_conus_sf, - 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$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, - barwidth = 20, - barheight = 1 - ), - format = "file" - ), + # tar_target( + # p3_perc_household_income_png, + # plot_census_map( + # census_data = p2_census_acs5sub_income_data[[1]], + # percent_leg = TRUE, + # var = 'percent', + # conus_sf = p1_conus_sf, + # 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$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, + # barwidth = 20, + # barheight = 1 + # ), + # format = "file" + # ), - tar_target( - p3_tot_latino_png, - plot_census_map( - census_data = p2_perc_census_acs5_layers_sf[[4]], - percent_leg = FALSE, - var = 'estimate', - conus_sf = p1_conus_sf, - outfile_path = "3_visualize/out/tot_hispanic_census_2022.png", - leg_title = "Total Hispanic, 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 = 20, - barheight = 1 - ), - format = "file" - ), + # tar_target( + # p3_tot_latino_png, + # plot_census_map( + # census_data = p2_perc_census_acs5_layers_sf[[4]], + # percent_leg = FALSE, + # var = 'estimate', + # conus_sf = p1_conus_sf, + # outfile_path = "3_visualize/out/tot_hispanic_census_2022.png", + # leg_title = "Total Hispanic, 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 = 20, + # barheight = 1 + # ), + # format = "file" + # ), tar_target( p3_perc_latino_png, @@ -87,33 +87,14 @@ p3_targets <- list( # Household related maps tar_target( - p3_total_households_png, + p3_perc_occ_households_png, plot_census_map( - census_data = p2_census_acs5sub_household_data[[1]], - percent_leg = FALSE, - var = 'estimate', - conus_sf = p1_conus_sf, - 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$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 = 20, - barheight = 1 - ), - format = "file" - ), - tar_target( - p3_female_households_png, - plot_census_map( - census_data = p2_census_acs5sub_household_data[[2]], - percent_leg = FALSE, + census_data = p2_census_acs5profile_household_sf, + percent_leg = TRUE, var = 'estimate', conus_sf = p1_conus_sf, - outfile_path = "3_visualize/out/tot_female_households_2022.png", - leg_title = "Total female households, 2022", + outfile_path = "3_visualize/out/perc_occupied_households_2022.png", + leg_title = "Percent occupied housing units, 2022", viz_config_df = p0_viz_config_df, viz_config_pal = p0_viz_config_pal$demographic_characteristics, width = p0_viz_config_df$width_desktop, @@ -124,6 +105,26 @@ p3_targets <- list( ), format = "file" ), + # tar_target( + # p3_female_households_png, + # plot_census_map( + # census_data = p2_census_acs5sub_household_data[[2]], + # percent_leg = FALSE, + # var = 'estimate', + # conus_sf = p1_conus_sf, + # 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$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 = 20, + # barheight = 1 + # ), + # format = "file" + # ), + tar_target( p3_median_rent_png, plot_census_map( @@ -145,125 +146,125 @@ p3_targets <- list( ), # 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$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, - barwidth = 20, - barheight = 1 - ), - 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$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, - barwidth = 20, - barheight = 1 - ), - 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$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, - barwidth = 20, - barheight = 1 - ), - 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$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, - barwidth = 20, - barheight = 1 - ), - 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$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, - barwidth = 20, - barheight = 1 - ), - 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$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, - barwidth = 20, - barheight = 1 - ), - format = "file" -), +# 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$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, +# barwidth = 20, +# barheight = 1 +# ), +# 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$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, +# barwidth = 20, +# barheight = 1 +# ), +# 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$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, +# barwidth = 20, +# barheight = 1 +# ), +# 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$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, +# barwidth = 20, +# barheight = 1 +# ), +# 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$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, +# barwidth = 20, +# barheight = 1 +# ), +# 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$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, +# barwidth = 20, +# barheight = 1 +# ), +# format = "file" +# ), # disability maps tar_target( @@ -282,27 +283,27 @@ tar_target( font_size = p0_viz_config_df$font_size_desktop, barwidth = 20, barheight = 1 - ), - 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 = 20, - barheight = 1 ), 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 = 20, +# barheight = 1 +# ), +# 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 311f876809e8bb66e66eb14f2197dd330aea7d48..cf4bf02d7fb5cb15ca2d57ad7ef5b49774fb616a 100644 --- a/3_visualize/src/plot_utils.R +++ b/3_visualize/src/plot_utils.R @@ -61,7 +61,6 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, ) } - census_legend <- get_legend(census_map) background_color = "white" plot_margin = 0.025 @@ -72,28 +71,27 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, var, gp = grid::gpar(fill = background_color, alpha = 1, col = background_color ) ) - - # compose final plot - final_map <- ggdraw(ylim = c(0,1), - xlim = c(0,1)) + - # White background - draw_grob(canvas, - x = 0, y = 1, - height = height, width = width, - hjust = 0, vjust = 1) + - # Add main plot - draw_plot(census_map + theme(legend.position="none"), - x = -0.01, - y = 0.08, - height = 0.98, - width = (1-plot_margin)*1.03) + - # Add legend - draw_plot(census_legend, - x = 0.48, - y = 0.02, - height = 0.09 , - width = 0.1 - plot_margin) - + census_legend <- get_plot_component(census_map, 'guide-box', return_all = TRUE) + # compose final plot + final_map <- ggdraw(ylim = c(0,1), + xlim = c(0,1)) + + # White background + draw_grob(canvas, + x = 0, y = 1, + height = height, width = width, + hjust = 0, vjust = 1) + + # Add main plot + draw_plot(census_map + theme(legend.position="none"), + x = -0.01, + y = 0.08, + height = 0.98, + width = (1-plot_margin)*1.03) + + # Add legend + draw_plot(census_legend[[3]], + x = 0.48, + y = 0.02, + height = 0.09 , + width = 0.1 - plot_margin) ggsave(outfile_path, final_map, width = width, height = height, dpi = viz_config_df$dpi, bg = viz_config_df$bg_col, units = "in") diff --git a/_targets.R b/_targets.R index ad936431b191917f2650804d4b8923db7455fc9e..6003b0d05f1039543b438c1ddaa84b7b76ca8a2c 100644 --- a/_targets.R +++ b/_targets.R @@ -13,7 +13,8 @@ tar_option_set(packages = c('tidyverse', 'sysfonts', 'showtext', 'readr', - 'cowplot')) + 'cowplot', + 'rmapshaper')) # Phase target makefiles source("0_config.R") diff --git a/src/assets/images/perc_occupied_households_2022.png b/src/assets/images/perc_occupied_households_2022.png new file mode 100644 index 0000000000000000000000000000000000000000..0e859385083d54244e87e2233821e4ac4a31d9fa Binary files /dev/null and b/src/assets/images/perc_occupied_households_2022.png differ diff --git a/src/assets/images/tot_female_households_2022.png b/src/assets/images/tot_female_households_2022.png deleted file mode 100644 index f35af0a28db9b1dd42b6a47e3caadf6a3e30bed3..0000000000000000000000000000000000000000 Binary files a/src/assets/images/tot_female_households_2022.png and /dev/null differ diff --git a/src/assets/images/tot_households_2022.png b/src/assets/images/tot_households_2022.png deleted file mode 100644 index acbd504f30f26f5c6f5a9d0fd0e49193b34c2f24..0000000000000000000000000000000000000000 Binary files a/src/assets/images/tot_households_2022.png and /dev/null differ diff --git a/src/components/Maps.vue b/src/components/Maps.vue index fbc33e4bcf0e73d0d9e135b0e313c49f58ffbef3..11476cfd14881d76ffa1403ccbcb6f1dd1ed6cd7 100644 --- a/src/components/Maps.vue +++ b/src/components/Maps.vue @@ -10,8 +10,8 @@ <button class="accordion households-accordion active">Household sizes<span class="symbol">-</span></button> <div class="panel households-panel"> <p v-html="mapText.paragraph1"></p> - <img src="@/assets/images/tot_households_2022.png" alt="Choropleth map of total households in the contiguous United States aggregated at the county level where counties with the greatest total households in dark blue include Los Angeles County, California (3,363,093), Harris County, Texas (1,692,896) and Maricopa County, Arizona (1,665,560). Data provided by 2022 American Community Survey, U.S. Census Bureau."> - <figcaption>County choropleth map of contiguous U.S. displaying total households, using 2022 U.S. Census Bureau data, where counties with the greatest total households, in dark blue, include Los Angeles County, California (3,363,093), Harris County, Texas (1,692,896) and Maricopa County, Arizona (1,665,560).</figcaption> + <img src="@/assets/images/perc_occupied_households_2022.png" alt="Choropleth map of percent occupied housing units in the contiguous United States aggregated at the county level where counties with the greatest percent of occupied housing units in dark blue include Dakota County, Minnesota (97.3%), Lincoln County, South Dakota (97.3%) and Scott County, Minnesota (97%). Data provided by 2022 American Community Survey, U.S. Census Bureau."> + <figcaption>County choropleth map of contiguous U.S. displaying percent occupied housing units, using 2022 U.S. Census Bureau data, where counties with the greatest percent of occupied housing units, in dark blue, include Dakota County, Minnesota (97.3%), Lincoln County, South Dakota (97.3%) and Scott County, Minnesota (97%).</figcaption> </div> <button class="accordion latino-accordion">Hispanic populations<span class="symbol">+</span></button>