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
de77d0cd
Commit
de77d0cd
authored
1 year ago
by
Azadpour, Elmera
Browse files
Options
Downloads
Patches
Plain Diff
add viz targets/fxns
parent
db9bea10
No related branches found
No related tags found
1 merge request
!4
Add census processing and viz to pipeline
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
3_visualize.R
+147
-2
147 additions, 2 deletions
3_visualize.R
3_visualize/src/plot_utils.R
+45
-0
45 additions, 0 deletions
3_visualize/src/plot_utils.R
with
192 additions
and
2 deletions
3_visualize.R
+
147
−
2
View file @
de77d0cd
# source('1_fetch/src/file_utils.R')
source
(
'3_visualize/src/plot_utils.R'
)
# source('3_visualize/src/plot_utils.R')
p3_targets
<-
list
(
p3_targets
<-
list
(
tar_target
(
p3_med_income_png
,
plot_census_map
(
census_data
=
p2_med_income_sf
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/med_income_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Median household income\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
),
tar_target
(
p3_tot_black_png
,
plot_census_map
(
census_data
=
p2_tot_black_sf
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_black_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Total Black\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
),
tar_target
(
p3_perc_black_png
,
plot_census_map
(
census_data
=
p2_perc_black_sf
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_black_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Percent Black\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
),
tar_target
(
p3_tot_latino_png
,
plot_census_map
(
census_data
=
p2_tot_latino_sf
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_latino_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Total Latino\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
),
tar_target
(
p3_perc_latino_png
,
plot_census_map
(
census_data
=
p2_perc_latino_sf
,
var
=
'percent'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/perc_latino_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Percent Latino\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
),
tar_target
(
p3_tot_male_png
,
plot_census_map
(
census_data
=
p2_tot_male_sf
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_male_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Total Male\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
),
tar_target
(
p3_tot_female_png
,
plot_census_map
(
census_data
=
p2_tot_female_sf
,
var
=
'estimate'
,
conus_sf
=
p1_conus_sf
,
outfile_path
=
"3_visualize/out/tot_female_census_2022.png"
,
pal
=
"OrRd"
,
leg_title
=
"Total Female\n2022"
,
width
=
6
,
height
=
4
,
dpi
=
300
,
counties_outline_col
=
"grey80"
,
conus_outline_col
=
'grey50'
,
bg_col
=
"white"
,
load_font
=
'Source Sans Pro'
,
font_size
=
10
),
format
=
"file"
)
)
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
3_visualize/src/plot_utils.R
0 → 100644
+
45
−
0
View file @
de77d0cd
# Map census data
#'
#' @param census_data, dataframe of census data for specified variable of interest
#' @param conus_sf, sf of conus states outline
#' @param pal, assign map palette
#' @param leg_title, character string for legend title
#' @param outfile_path, outfile path for pngs
#' @param width, set png width
#' @param height, set png height
#' @param dpi, set png dots per inches
#' @param counties_outline_col, assign color to counties outline
#' @param conus_outline_col, assign color to conus outline
#' @param bg_col, assign background color for maps
#' @param load_font, assign font name
plot_census_map
<-
function
(
census_data
,
conus_sf
,
pal
,
leg_title
,
outfile_path
,
width
,
height
,
dpi
,
counties_outline_col
,
conus_outline_col
,
bg_col
,
load_font
,
font_size
,
var
){
font_legend
<-
load_font
font_add_google
(
font_legend
)
showtext_opts
(
dpi
=
300
,
regular.wt
=
200
,
bold.wt
=
700
)
showtext_auto
(
enable
=
TRUE
)
census_map
<-
census_data
|>
ggplot
(
aes
(
fill
=
.data
[[
var
]]))
+
geom_sf
(
color
=
counties_outline_col
,
linewidth
=
0.05
)
+
geom_sf
(
data
=
conus_sf
,
fill
=
NA
,
color
=
conus_outline_col
,
linewidth
=
0.2
,
linetype
=
"solid"
)
+
theme_void
()
+
scale_fill_distiller
(
palette
=
pal
,
direction
=
1
,
name
=
leg_title
,
limits
=
c
(
0
,
max
(
census_data
[[
var
]],
na.rm
=
TRUE
)),
labels
=
scales
::
comma
)
+
theme
(
text
=
element_text
(
family
=
font_legend
,
size
=
font_size
),
legend.margin
=
margin
(
r
=
10
))
ggsave
(
outfile_path
,
census_map
,
width
=
width
,
height
=
height
,
dpi
=
dpi
,
bg
=
bg_col
)
return
(
outfile_path
)
}
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