source('_data/setup.R')
suppressPackageStartupMessages({
require(randomForest)
require(pdp)
require(BAMMtools)
require(pROC)
require(PRROC)
require(ggbeeswarm)
require(iml)
require(ggrepel)
})
<- function(variable, value) {
label_wrap lapply(strwrap(as.character(value), width=25, simplify=FALSE), paste, collapse="\n")
}
theme_set(theme_classic() + theme(text = element_text(family = 'Segoe UI', size = 9)))
<- function(df, xname) df %>%
transfm mutate(x = if(grepl('log', xname)) 10^get(xname)-1 else get(xname))
# colors.hev <- scico(5, palette = 'lajolla')[2:4]
<- scico(8, palette = 'lapaz')[c(7,5,3)]
colors.hev # colors.hev <- c(
# rgb(242,168,168, maxColorValue = 255),
# rgb(164,24,24, maxColorValue = 255),
# rgb(75,13,13, maxColorValue = 255))
<- scico(7,palette='roma')[2]
ctycol <- roma.colors[5] saccol
<- 1000 nsamp
## 1981 - all variables
load('_results/county_rfmodel_1981.Rdata')
.1981 <- f.rf
f.cty.1981 <- df.pca
df.pca.cty.1981 <- df.train
df.train.cty.1981 <- df.test
df.test.cty.1981 <- obs.id
obs.cty.1981 <- sample(1:nrow(df.pca.cty.1981), nsamp)
samp.cty
load(paste0('_results/county_iml_1981.Rdata'))
.1981 <- iml.ale
ale.ctyload(paste0('_results/county_shap_1981.Rdata'))
.1981 <- shap shap.cty
## 2009 - all variables
load('_results/county_rfmodel_2009.Rdata')
.2009 <- f.rf
f.cty.2009 <- df.pca
df.pca.cty.2009 <- df.train
df.train.cty.2009 <- df.test
df.test.cty.2009 <- obs.id
obs.cty.2009 <- sample(1:nrow(df.pca.cty.2009), nsamp)
samp.cty
load(paste0('_results/county_iml_2009.Rdata'))
.2009 <- iml.ale
ale.ctyload(paste0('_results/county_shap_2009.Rdata'))
.2009 <- shap shap.cty
## 1981 - all variables
load('_results/sac_rfmodel_1981.Rdata')
.1981 <- f.rf
f.sac.1981 <- df.pca
df.pca.sac.1981 <- df.train
df.train.sac.1981 <- df.test
df.test.sac.1981 <- obs.id
obs.sac.1981 <- sample(1:nrow(df.pca.sac.1981), nsamp)
samp.sac
load(paste0('_results/sac_iml_1981.Rdata'))
.1981 <- iml.ale
ale.sacload(paste0('_results/sac_shap_1981.Rdata'))
.1981 <- shap shap.sac
## 2009 - all variables
load('_results/sac_rfmodel_2009.Rdata')
.2009 <- f.rf
f.sac.2009 <- df.pca
df.pca.sac.2009 <- df.train
df.train.sac.2009 <- df.test
df.test.sac.2009 <- obs.id
obs.sac.2009 <- sample(1:nrow(df.pca.sac.2009), nsamp)
samp.sac
load(paste0('_results/sac_iml_2009.Rdata'))
.2009 <- iml.ale
ale.sacload(paste0('_results/sac_shap_2009.Rdata'))
.2009 <- shap shap.sac
rm(f.rf, df.pca, df.train, df.test, obs.id, iml.ale, shap)
.1981 <- shap.cty.1981 %>%
plotimp.cty%>% select(-y) %>%
as.data.frame summarize(across(everything(), ~mean(abs(.)))) %>%
pivot_longer(everything(), names_to = 'varnames', values_to = 'shap') %>%
left_join(dimension, by = c('varnames' = 'var')) %>%
arrange(shap) %>%
filter(shap >= shap[varnames=='noise']) %>%
mutate(
rank = nrow(.):1,
varnames = factor(varnames, levels = varnames),
fullname = factor(fullname, levels = fullname),
shap = c(0, shap[-1]),
dim = factor(dim, levels = c('H','E','V')))
.2009 <- shap.cty.2009 %>%
plotimp.cty%>% select(-y) %>%
as.data.frame summarize(across(everything(), ~mean(abs(.)))) %>%
pivot_longer(everything(), names_to = 'varnames', values_to = 'shap') %>%
left_join(dimension, by = c('varnames' = 'var')) %>%
arrange(shap) %>%
filter(shap >= shap[varnames=='noise']) %>%
mutate(
rank = nrow(.):1,
varnames = factor(varnames, levels = varnames),
fullname = factor(fullname, levels = fullname),
shap = c(0, shap[-1]),
dim = factor(dim, levels = c('H','E','V')))
.1981 <- shap.sac.1981 %>%
plotimp.sac%>% select(-y) %>%
as.data.frame summarize(across(everything(), ~mean(abs(.)))) %>%
pivot_longer(everything(), names_to = 'varnames', values_to = 'shap') %>%
left_join(dimension, by = c('varnames' = 'var')) %>%
arrange(shap) %>%
filter(shap >= shap[varnames=='noise']) %>%
mutate(
rank = nrow(.):1,
varnames = factor(varnames, levels = varnames),
fullname = factor(fullname, levels = fullname),
shap = c(0, shap[-1]),
dim = factor(dim, levels = c('H','E','V')))
.2009 <- shap.sac.2009 %>%
plotimp.sac%>% select(-y) %>%
as.data.frame summarize(across(everything(), ~mean(abs(.)))) %>%
pivot_longer(everything(), names_to = 'varnames', values_to = 'shap') %>%
left_join(dimension, by = c('varnames' = 'var')) %>%
arrange(shap) %>%
filter(shap >= shap[varnames=='noise']) %>%
mutate(
rank = nrow(.):1,
varnames = factor(varnames, levels = varnames),
fullname = factor(fullname, levels = fullname),
shap = c(0, shap[-1]),
dim = factor(dim, levels = c('H','E','V')))
<-
plotimp.all rbind(
.1981 %>% mutate(spat = 'Statewide', temp = '1981-2021'),
plotimp.cty.2009 %>% mutate(spat = 'Statewide', temp = '2009-2021'),
plotimp.cty.1981 %>% mutate(spat = 'Sacramento', temp = '1981-2021'),
plotimp.sac.2009 %>% mutate(spat = 'Sacramento', temp = '2009-2021')) %>%
plotimp.sacfilter(varnames != 'noise')
## set plot parameters
<- 0.5
ptsize <- 0.75
linesize <- 'grey50'
ptcol
<- c(-0.3, 0.25)
rangehaz <- c(-0.15, 0.1)
rangeexp <- c(-0.15, 0.1)
rangevuln
<- ggplot() +
gbase geom_hline(yintercept = 0, color = 'grey50', size = 0.25) +
scale_y_continuous(
'SHAP Feature Contribution',
labels = percent,
sec.axis = sec_axis(~., name = 'Accumulated Local Effects', labels = percent)) +
theme(
text = element_text(size = 9),
panel.grid.major.y = element_line(size = 0.25),
axis.line.y.right = element_line(),
axis.ticks.y.right = element_line(),
axis.title.y.left = element_blank(),
axis.title.y.right = element_blank(),
axis.text.y.left = element_blank(),
axis.text.y.right = element_blank())
.1981 %>%
plotimp.ctyfilter(dim == 'H') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "logprecip_total" "maxivt" "duration"
<- 'logprecip_total'
xname <- gbase +
g1h geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Hazard',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(ylim = rangehaz) +
theme(
plot.title = element_text(face = 'bold', color = '#dda077'),
axis.text.y.left = element_text())
<- 'maxivt'
xname <- gbase +
g2h geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
coord_cartesian(xlim = c(250,NA), ylim = rangehaz) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(breaks = 250*(0:10), expand = expansion(mult = c(0,0.05)))
<- 'duration'
xname <- gbase +
g3h geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(xlim = c(0,200), ylim = rangehaz) +
theme(
axis.text.y.right = element_text())
.1981 %>%
plotimp.ctyfilter(dim == 'E') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "loghu" "pop_pct_floodplain" "pct_sfh"
<- 'loghu'
xname <- gbase +
g1e geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Exposure',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_log10(
breaks = 10^(1:10),
labels = c('10','100','1K','10K','100K','1M','10M','100M','1B','10B')) +
annotation_logticks(sides = 'b', size = 0.25, color = 'grey25') +
coord_cartesian(ylim = rangeexp) +
theme(
plot.title = element_text(face = 'bold', color = '#71938f'),
axis.title.y.left = element_text(),
axis.text.y.left = element_text())
<- 'pop_pct_floodplain'
xname <- gbase +
g2e geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(xlim = c(0,0.4), ylim = rangeexp)
<- 'pct_sfh'
xname <- gbase +
g3e geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 24)) +
scale_x_continuous(labels = percent, expand = expansion(mult = 0.05)) +
coord_cartesian(xlim = c(0.4,NA), ylim = rangeexp) +
theme(
axis.title.y.right = element_text(),
axis.text.y.right = element_text())
.1981 %>%
plotimp.ctyfilter(dim == 'V') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "CRS" "hhincome22" "cal_polburd"
<- 'CRS'
xname <- gbase +
g1v geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = jitter(x), y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(.borders > 2) %>%
mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Vulnerability',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln) +
scale_x_continuous(breaks = 2:10) +
theme(
plot.title = element_text(face = 'bold', color = colors.hev[3]),
axis.text.y.left = element_text())
<- 'hhincome22'
xname <- gbase +
g2v geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = comma_format(scale = 1e-3, prefix = '$', suffix = 'K')) +
coord_cartesian(ylim = rangevuln)
<- 'cal_polburd'
xname <- gbase +
g3v geom_point(
data = transfm(df.pca.cty.1981, xname) %>% slice(samp.cty.1981) %>%
mutate(y = shap.cty.1981 %>% data.frame %>% slice(samp.cty.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.1981[,xname],0.025) &
.borders < quantile(df.pca.cty.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln) +
theme(
axis.text.y.right = element_text())
+ g2h + g3h + g1e + g2e + g3e + g1v + g2v + g3v +
g1h plot_layout(nrow = 3) +
plot_annotation(tag_levels = 'a', tag_prefix = '(', tag_suffix = ')') &
theme(
legend.position = 'none',
plot.tag = element_text(face = 'bold'),
plot.tag.position = c(0.12,0.975)) #1.01 without the title
ggsave('_figures/fig4_impact_county1981.png', width = 6, height = 6)
.2009 %>%
plotimp.ctyfilter(dim == 'H') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "logprecip_total" "maxivt" "logprecip_lag03"
<- 'logprecip_total'
xname <- gbase +
g1h geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Hazard',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(ylim = rangehaz) +
theme(
plot.title = element_text(face = 'bold', color = '#dda077'),
axis.text.y.left = element_text())
<- 'maxivt'
xname <- gbase +
g2h geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
coord_cartesian(xlim = c(250,NA), ylim = rangehaz) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(breaks = 250*(0:10), expand = expansion(mult = c(0,0.05)))
<- 'logprecip_lag03'
xname <- gbase +
g3h geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(xlim = c(0,150), ylim = rangehaz) +
theme(
axis.text.y.right = element_text())
.2009 %>%
plotimp.ctyfilter(dim == 'E') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "loghu" "pop_pct_floodplain"
<- 'loghu'
xname <- gbase +
g1e geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Exposure',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_log10(
breaks = 10^(1:10),
labels = c('10','100','1K','10K','100K','1M','10M','100M','1B','10B')) +
annotation_logticks(sides = 'b', size = 0.25, color = 'grey25') +
coord_cartesian(ylim = rangeexp) +
theme(
plot.title = element_text(face = 'bold', color = '#71938f'),
axis.title.y.left = element_text(),
axis.text.y.left = element_text())
<- 'pop_pct_floodplain'
xname <- gbase +
g2e geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(xlim = c(0,0.4), ylim = rangeexp)
<- ggplot() +
g3e geom_hline(yintercept = 0, color = 'white') +
scale_y_continuous(
'SHAP Feature Contribution',
labels = percent,
sec.axis = sec_axis(~., name = 'Accumulated Local Effects', labels = percent)) +
coord_cartesian(xlim = c(0.4,NA), ylim = rangeexp) +
theme_classic() +
theme(
text = element_text(family = 'Segoe UI', size = 9),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.title.y.left = element_blank(),
axis.text.y.left = element_blank(),
axis.line.y.right = element_line(),
axis.ticks.y.right = element_line(),
axis.title.y.right = element_text(),
axis.text.y.right = element_text())
.2009 %>%
plotimp.ctyfilter(dim == 'V') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "cdc_theme2" "cdc_theme4" "cal_popchar"
<- 'cdc_theme2'
xname <- gbase +
g1v geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = jitter(x), y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Vulnerability',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln) +
theme(
plot.title = element_text(face = 'bold', color = colors.hev[3]),
axis.text.y.left = element_text())
<- 'cdc_theme4'
xname <- gbase +
g2v geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln)
<- 'cal_popchar'
xname <- gbase +
g3v geom_point(
data = transfm(df.pca.cty.2009, xname) %>% slice(samp.cty.2009) %>%
mutate(y = shap.cty.2009 %>% data.frame %>% slice(samp.cty.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.cty.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.cty.2009[,xname],0.025) &
.borders < quantile(df.pca.cty.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln) +
theme(
axis.text.y.right = element_text())
+ g2h + g3h + g1e + g2e + g3e + g1v + g2v + g3v +
g1h plot_layout(nrow = 3) +
plot_annotation(tag_levels = 'a', tag_prefix = '(', tag_suffix = ')') &
theme(
legend.position = 'none',
plot.tag = element_text(face = 'bold'),
plot.tag.position = c(0.12,0.975)) #1.01 without the title
ggsave('_figures/fig4_impact_county2009.png', width = 6, height = 6)
.1981 %>%
plotimp.sacfilter(dim == 'H') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "logprecip_total" "maxivt" "sm_lag03"
<- 'logprecip_total'
xname <- gbase +
g1h geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Hazard',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(ylim = rangehaz) +
theme(
plot.title = element_text(face = 'bold', color = '#dda077'),
axis.text.y.left = element_text())
<- 'maxivt'
xname <- gbase +
g2h geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
coord_cartesian(xlim = c(250,NA), ylim = rangehaz) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(breaks = 250*(0:10), expand = expansion(mult = c(0,0.05)))
<- 'sm_lag03'
xname <- gbase +
g3h geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(ylim = rangehaz) +
theme(
axis.text.y.right = element_text())
.1981 %>%
plotimp.sacfilter(dim == 'E') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "pop_pct_floodplain" "loghu" "pct_sfh"
<- 'pop_pct_floodplain'
xname <- gbase +
g1e geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Exposure',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(ylim = rangeexp) +
theme(
plot.title = element_text(face = 'bold', color = '#71938f'),
axis.title.y.left = element_text(),
axis.text.y.left = element_text())
<- 'loghu'
xname <- gbase +
g2e geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_log10() +
annotation_logticks(sides = 'b', size = 0.25, color = 'grey25') +
coord_cartesian(ylim = rangeexp)
<- 'pct_sfh'
xname <- gbase +
g3e geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(ylim = rangeexp) +
theme(
axis.title.y.right = element_text(),
axis.text.y.right = element_text())
.1981 %>%
plotimp.sacfilter(dim == 'V') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "med_struct_age" "pct_mobile" "CRS"
<- 'med_struct_age'
xname <- gbase +
g1v geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = jitter(x), y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Vulnerability',
x = dimension$fullname[dimension$var==xname] %>% paste(.,'(years)') %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln) +
theme(
plot.title = element_text(face = 'bold', color = colors.hev[3]),
axis.text.y.left = element_text())
<- 'pct_mobile'
xname <- gbase +
g2v geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.1981[,xname],0.025) &
.borders < quantile(df.pca.sac.1981[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(xlim = c(0,0.35), ylim = rangevuln)
<- 'CRS'
xname <- gbase +
g3v geom_point(
data = transfm(df.pca.sac.1981, xname) %>% slice(samp.sac.1981) %>%
mutate(y = shap.sac.1981 %>% data.frame %>% slice(samp.sac.1981) %>% pull(xname)),
aes(x = jitter(x), y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.1981 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(.borders > 2) %>%
mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
coord_cartesian(ylim = rangevuln) +
scale_x_continuous(breaks = 2:10) +
theme(
axis.text.y.right = element_text())
+ g2h + g3h + g1e + g2e + g3e + g1v + g2v + g3v +
g1h plot_layout(nrow = 3) +
plot_annotation(tag_levels = 'a', tag_prefix = '(', tag_suffix = ')') &
theme(
legend.position = 'none',
plot.tag = element_text(face = 'bold'),
plot.tag.position = c(0.12,0.975)) #1.01 without the title
ggsave('_figures/fig4_impact_sac1981.png', width = 6, height = 6)
.2009 %>%
plotimp.sacfilter(dim == 'H') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "maxivt" "logprecip_total" "logprecip_lag03"
<- 'maxivt'
xname <- gbase +
g1h geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
coord_cartesian(xlim = c(250,NA), ylim = rangehaz) +
labs(
title = 'Hazard',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(breaks = 250*(0:10), expand = expansion(mult = c(0,0.05))) +
theme(
plot.title = element_text(face = 'bold', color = '#dda077'),
axis.text.y.left = element_text())
<- 'logprecip_total'
xname <- gbase +
g2h geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(ylim = rangehaz)
<- 'logprecip_lag03'
xname <- gbase +
g3h geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.05))) +
coord_cartesian(ylim = rangehaz) +
theme(
axis.text.y.right = element_text())
.2009 %>%
plotimp.sacfilter(dim == 'E') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "pop_pct_floodplain" "loghu" "pct_sfh"
<- 'pop_pct_floodplain'
xname <- gbase +
g1e geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Exposure',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(ylim = rangeexp) +
theme(
plot.title = element_text(face = 'bold', color = '#71938f'),
axis.title.y.left = element_text(),
axis.text.y.left = element_text())
<- 'loghu'
xname <- gbase +
g2e geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_log10() +
annotation_logticks(sides = 'b', size = 0.25, color = 'grey25') +
coord_cartesian(ylim = rangeexp)
<- 'pct_sfh'
xname <- gbase +
g3e geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(ylim = rangeexp) +
theme(
axis.title.y.right = element_text(),
axis.text.y.right = element_text())
.2009 %>%
plotimp.sacfilter(dim == 'V') %>% arrange(desc(shap)) %>%
head(3) %>% pull(varnames) %>% paste
## [1] "pct_over40" "pct_mobile" "cdc_theme2"
<- 'pct_over40'
xname <- gbase +
g1v geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = jitter(x), y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
title = 'Vulnerability',
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(ylim = rangevuln) +
theme(
plot.title = element_text(face = 'bold', color = colors.hev[3]),
axis.text.y.left = element_text())
<- 'pct_mobile'
xname <- gbase +
g2v geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(labels = percent, expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(xlim = c(0,0.35), ylim = rangevuln)
<- 'cdc_theme2'
xname <- gbase +
g3v geom_point(
data = transfm(df.pca.sac.2009, xname) %>% slice(samp.sac.2009) %>%
mutate(y = shap.sac.2009 %>% data.frame %>% slice(samp.sac.2009) %>% pull(xname)),
aes(x = x, y = y), size = ptsize, color = ptcol, alpha = 0.25) +
geom_line(
data = ale.sac.2009 %>%
filter(.feature == xname) %>%
mutate(.borders = toNumber(.borders)) %>%
filter(
> quantile(df.pca.sac.2009[,xname],0.025) &
.borders < quantile(df.pca.sac.2009[,xname],0.975)) %>%
.borders mutate(x = ifelse(grepl('log',.feature), 10^.borders-1, .borders)),
aes(x = x, y = .value), size = linesize) +
labs(
x = dimension$fullname[dimension$var==xname] %>% str_wrap(width = 20)) +
scale_x_continuous(expand = expansion(mult = c(0.02,0.02))) +
coord_cartesian(ylim = rangevuln) +
theme(
axis.text.y.right = element_text())
+ g2h + g3h + g1e + g2e + g3e + g1v + g2v + g3v +
g1h plot_layout(nrow = 3) +
plot_annotation(tag_levels = 'a', tag_prefix = '(', tag_suffix = ')') &
theme(
legend.position = 'none',
plot.tag = element_text(face = 'bold'),
plot.tag.position = c(0.12,0.975)) #1.01 without the title
ggsave('_figures/fig4_impact_sac2009.png', width = 6, height = 6)