Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vulnerability-indicators
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Water Mission Area
VizLab
vulnerability-indicators
Commits
001b17b8
Commit
001b17b8
authored
1 year ago
by
Azadpour, Elmera
Browse files
Options
Downloads
Patches
Plain Diff
update maps
parent
762362f7
No related branches found
No related tags found
1 merge request
!12
Add disaggregated census data/maps
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
3_visualize.R
+179
-132
179 additions, 132 deletions
3_visualize.R
3_visualize/src/plot_utils.R
+6
-4
6 additions, 4 deletions
3_visualize/src/plot_utils.R
with
185 additions
and
136 deletions
3_visualize.R
+
179
−
132
View file @
001b17b8
source
(
'3_visualize/src/plot_utils.R'
)
# For case studies approach: select one demographic characteristic (hispanic/latino),
p3_targets
<-
list
(
tar_target
(
p3_med_income_png
,
plot_census_map
(
census_data
=
p2_perc_census_acs5_layers_sf
[[
2
]],
percent_leg
=
FALSE
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/med_income_census_2022.png"
,
leg_title
=
"Median household income, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
tar_target
(
p3_tot_black_png
,
plot_census_map
(
census_data
=
p2_perc_census_acs5_layers_sf
[[
3
]],
percent_leg
=
FALSE
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_black_census_2022.png"
,
leg_title
=
"Total Black, 2022"
,
viz_config_df
=
viz_config_df
viz_config_df
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_positive
),
format
=
"file"
),
tar_target
(
p3_perc_
black
_png
,
p3_perc_
household_income_map
_png
,
plot_census_map
(
census_data
=
p2_
perc_
census_acs5
_layers_sf
[[
3
]],
census_data
=
p2_census_acs5
sub_income_data
[[
1
]],
percent_leg
=
TRUE
,
var
=
'percent'
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_black_census_2022.png"
,
leg_title
=
"Percent Black, 2022"
,
viz_config_df
=
viz_config_df
outfile_path
=
"3_visualize/out/perc_household_income_2022.png"
,
leg_title
=
"Percent allocated household income in the past 12 months, 2022"
,
viz_config_df
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_positive
),
format
=
"file"
),
#
# tar_target(
# p3_tot_black_png,
# plot_census_map(
# census_data = p2_perc_census_acs5_layers_sf[[3]],
# percent_leg = FALSE,
# var = 'estimate',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/tot_black_census_2022.png",
# leg_title = "Total Black, 2022",
# viz_config_df = viz_config_df,
# viz_config_pal = viz_config_pal$pal_positive
# ),
# format = "file"
# ),
# tar_target(
# p3_perc_black_png,
# plot_census_map(
# census_data = p2_perc_census_acs5_layers_sf[[3]],
# percent_leg = TRUE,
# var = 'percent',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/perc_black_census_2022.png",
# leg_title = "Percent Black, 2022",
# viz_config_df = viz_config_df,
# viz_config_pal = viz_config_pal$pal_positive
# ),
# format = "file"
# ),
tar_target
(
p3_tot_latino_png
,
...
...
@@ -53,7 +68,8 @@ p3_targets <- list(
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_latino_census_2022.png"
,
leg_title
=
"Total Latino, 2022"
,
viz_config_df
=
viz_config_df
viz_config_df
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_positive
),
format
=
"file"
),
...
...
@@ -67,131 +83,162 @@ p3_targets <- list(
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_latino_census_2022.png"
,
leg_title
=
"Percent Latino, 2022"
,
viz_config_df
=
viz_config_df
viz_config_df
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_positive
),
format
=
"file"
),
tar_target
(
p3_tot_male_png
,
plot_census_map
(
census_data
=
p2_perc_census_acs5_layers_sf
[[
5
]],
percent_leg
=
FALSE
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_male_census_2022.png"
,
leg_title
=
"Total Male, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
# tar_target(
# p3_tot_male_png,
# plot_census_map(
# census_data = p2_perc_census_acs5_layers_sf[[5]],
# percent_leg = FALSE,
# var = 'estimate',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/tot_male_census_2022.png",
# leg_title = "Total Male, 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
#
# tar_target(
# p3_tot_female_png,
# plot_census_map(
# census_data = p2_perc_census_acs5_layers_sf[[6]],
# percent_leg = FALSE,
# var = 'estimate',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/tot_female_census_2022.png",
# leg_title = "Total Female, 2022",
# viz_config_df = viz_config_df,
# viz_config_pal = viz_config_pal$pal_positive
# ),
# format = "file"
# ),
# # Disaggregated maps
# # percent age maps
# tar_target(
# p3_perc_under_18_map_png,
# plot_census_map(
# census_data = p2_census_acs5sub_age_data[[1]],
# percent_leg = TRUE,
# var = 'percent',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/perc_pop_under_18_2022.png",
# leg_title = "Percent of Total Poulation Under 18, 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
# tar_target(
# p3_perc_18_24_map_png,
# plot_census_map(
# census_data = p2_census_acs5sub_age_data[[2]],
# percent_leg = TRUE,
# var = 'percent',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/perc_pop_under_18-24_2022.png",
# leg_title = "Percent of Total Poulation 18-24 years, 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
# tar_target(
# p3_perc_15_44_map_png,
# plot_census_map(
# census_data = p2_census_acs5sub_age_data[[3]],
# percent_leg = TRUE,
# var = 'percent',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/perc_pop_under_15-44_2022.png",
# leg_title = "Percent of Total Poulation 15-44 years, 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
# tar_target(
# p3_perc_60_plus_map_png,
# plot_census_map(
# census_data = p2_census_acs5sub_age_data[[4]],
# percent_leg = TRUE,
# var = 'percent',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/perc_pop_under_60_plus_2022.png",
# leg_title = "Percent of Total Poulation 60 years & plus, 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
# # education related map
# tar_target(
# p3_tot_18_24_highschool_education_map_png,
# plot_census_map(
# census_data = p2_census_acs5sub_education_data[[1]],
# percent_leg = FALSE,
# var = 'estimate',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/tot_education_18-24_highschool_2022.png",
# leg_title = "Total population 18-24 years\nhigh school graduate (includes equivalency), 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
# tar_target(
# p3_tot_25_plus_highschool_education_map_png,
# plot_census_map(
# census_data = p2_census_acs5sub_education_data[[2]],
# percent_leg = FALSE,
# var = 'estimate',
# conus_sf = p1_conus_sf,
# outfile_path = "3_visualize/out/tot_education_25-plus_highschool_2022.png",
# leg_title = "Total population 25 and older\nhigh school graduate (includes equivalency), 2022",
# viz_config_df = viz_config_df
# ),
# format = "file"
# ),
# Household related maps
tar_target
(
p3_tot
_female
_png
,
p3_tot
al_households
_png
,
plot_census_map
(
census_data
=
p2_
perc_
census_acs5
_layers_sf
[[
6
]],
census_data
=
p2_census_acs5
sub_household_data
[[
1
]],
percent_leg
=
FALSE
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_female_census_2022.png"
,
leg_title
=
"Total Female, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
# Disaggregated maps
# percent age maps
tar_target
(
p3_perc_under_18_map_png
,
plot_census_map
(
census_data
=
p2_census_acs5sub_age_data
[[
1
]],
percent_leg
=
TRUE
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_pop_under_18_2022.png"
,
leg_title
=
"Percent of Total Poulation Under 18, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
tar_target
(
p3_perc_18_24_map_png
,
plot_census_map
(
census_data
=
p2_census_acs5sub_age_data
[[
2
]],
percent_leg
=
TRUE
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_pop_under_18-24_2022.png"
,
leg_title
=
"Percent of Total Poulation 18-24 years, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
tar_target
(
p3_perc_15_44_map_png
,
plot_census_map
(
census_data
=
p2_census_acs5sub_age_data
[[
3
]],
percent_leg
=
TRUE
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_pop_under_15-44_2022.png"
,
leg_title
=
"Percent of Total Poulation 15-44 years, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
tar_target
(
p3_perc_60_plus_map_png
,
plot_census_map
(
census_data
=
p2_census_acs5sub_age_data
[[
4
]],
percent_leg
=
TRUE
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_pop_under_60_plus_2022.png"
,
leg_title
=
"Percent of Total Poulation 60 years & plus, 2022"
,
viz_config_df
=
viz_config_df
),
format
=
"file"
),
# percent income maps
tar_target
(
p3_perc_household_income_map_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 in the past 12 months, 2022"
,
viz_config_df
=
viz_config_df
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_households_2022.png"
,
leg_title
=
"Total households, 2022"
,
viz_config_df
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_positive
),
format
=
"file"
),
# education related map
tar_target
(
p3_
tot_18_24_highschool_education_map
_png
,
p3_
female_households
_png
,
plot_census_map
(
census_data
=
p2_census_acs5sub_
education
_data
[[
1
]],
census_data
=
p2_census_acs5sub_
household
_data
[[
2
]],
percent_leg
=
FALSE
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_education_18-24_highschool_2022.png"
,
leg_title
=
"Total population 18-24 years\nhigh school graduate (includes equivalency), 2022"
,
viz_config_df
=
viz_config_df
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
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_positive
),
format
=
"file"
),
tar_target
(
p3_
tot_25_plus_highschool_education_map
_png
,
p3_
median_rent
_png
,
plot_census_map
(
census_data
=
p2_census_acs5sub_
education
_data
[[
2
]],
census_data
=
p2_census_acs5sub_
household
_data
[[
3
]],
percent_leg
=
FALSE
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_education_25-plus_highschool_2022.png"
,
leg_title
=
"Total population 25 and older\nhigh school graduate (includes equivalency), 2022"
,
viz_config_df
=
viz_config_df
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/median_rent_2022.png"
,
leg_title
=
"Median gross rent, 2022"
,
viz_config_df
=
viz_config_df
,
viz_config_pal
=
viz_config_pal
$
pal_neg
),
format
=
"file"
)
...
...
This diff is collapsed.
Click to expand it.
3_visualize/src/plot_utils.R
+
6
−
4
View file @
001b17b8
...
...
@@ -4,9 +4,11 @@
#' @param conus_sf, sf of conus states outline
#' @param leg_title, character string for legend title
#' @param outfile_path, outfile path for pngs
#' @param viz_config_df `data.frame` with palette, width, height, counties outline color, conus outline color, background color, font nam, and font size
#' @param viz_config_df `data.frame` width, height, counties outline color, conus outline color, background color, font nam, and font size
#' @param viz_config_pal `data.frame` assign colors for postively and negatively correlated dimensions for census maps
#' @param percent_leg if else statement where if TRUE, apply 0-100 legend, otherwise retain 0 - max of variable name
plot_census_map
<-
function
(
census_data
,
conus_sf
,
leg_title
,
outfile_path
,
font_size
,
var
,
percent_leg
,
viz_config_df
){
plot_census_map
<-
function
(
census_data
,
conus_sf
,
leg_title
,
outfile_path
,
font_size
,
var
,
percent_leg
,
viz_config_df
,
viz_config_pal
){
font_legend
<-
viz_config_df
$
load_font
font_add_google
(
font_legend
)
...
...
@@ -37,7 +39,7 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, font
if
(
percent_leg
==
FALSE
)
{
census_map
<-
census_map
+
scale_fill_distiller
(
palette
=
viz_config_
df
$
pal
,
palette
=
viz_config_pal
,
direction
=
1
,
name
=
leg_title
,
limits
=
c
(
0
,
max
(
census_data
[[
var
]],
na.rm
=
TRUE
)),
...
...
@@ -46,7 +48,7 @@ plot_census_map <- function(census_data, conus_sf, leg_title, outfile_path, font
}
else
{
census_map
<-
census_map
+
scale_fill_distiller
(
palette
=
viz_config_
df
$
pal
,
palette
=
viz_config_pal
,
direction
=
1
,
name
=
leg_title
,
limits
=
c
(
0
,
100
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment