-
Notifications
You must be signed in to change notification settings - Fork 2
/
Risk_Interactions.R
209 lines (191 loc) · 11.3 KB
/
Risk_Interactions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
##==============================================================================
##
## Script creates conceptual graphs to show interactions among flood hazard,
## exposure, and risk
## All the values in this plot such as water levels, levee effect coefficient, logistic function
## and its parameters, etc. are hypothetical and to convey a concept.
##
## Authors: Iman Hosseini-Shakib ([email protected])
## Klaus Keller ([email protected])
## Recoded by: Vivek Srikrishnan ([email protected])
## Code verification: Matthew Lisk ([email protected])
##==============================================================================
## Copyright 2021 Iman Hosseini-Shakib and Klaus Keller
## This file is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This file is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file. If not, see <http://www.gnu.org/licenses/>.
##==============================================================================
rm(list=ls())
graphics.off()
# Packages used
if (!require('VGAM')) {install.packages('VGAM')}
if (!require('ggplot2')) {install.packages('ggplot2')}
if (!require('ggpubr')) {install.packages('ggpubr')}
if (!require('ggExtra')) {install.packages('ggExtra')}
library(VGAM)
library(ggplot2)
library(ggpubr)
library(ggExtra)
nsamp <- 1e6 # how many samples per distribution?
# A logistic function to mimic the S-shaped depth-damage curve with water levels (WL) and coefficients a and k
logistic <- function(WL,k,a){
(1/(1+exp(-k*WL)))^a
}
# Water level distribution characteristics
WL=1:1000 #hypothetical water levels
meanWL=525 #hypothetical mean water level for the stationary pdf
sdWL=65 #hypothetical standard deviation of the stationary pdf
meanWL_nonS=550 #hypothetical mean water level for the non-stationary pdf
sdWL_nonS=150 #hypothetical standard deviation of the non-stationary pdf
shapeWL_nonS=5 #hypothetical shape factor of the non-stationary pdf
# Hazard
WLbest=WL[meanWL] #hypothetical best guess stationary water level
# obtain samples from distributions
wl_stat_samp <- rnorm(nsamp,meanWL,sdWL) #hypothetical distribution of water levels - stationary with uncertainty
wl_nonstat_samp <- rskewnorm(nsamp,location=meanWL_nonS,scale=sdWL_nonS,shape=shapeWL_nonS) #hypothetical distribution of water levels - non-stationary with uncertainty
# Vulnerability
dmg_nolevee <- logistic((0.015*WL)-11,0.8,0.6) #hypothetical damages - without levee effect
LEV=1.3 #hypothetical levee effect coefficient
dmg_levee <- dmg_nolevee * LEV #hypothetical damages - with levee effect
# Risk
rsk_nounc_nolevee <- dmg_nolevee[WLbest] # hypothetical risk with stationary best guess hazard and depth-damage function without levee effect
rsk_stat_nolevee <- logistic((0.015*wl_stat_samp)-11, 0.8, 0.6) # hypothetical risk pdf with stationary with uncertainty pdf and depth-damage function without levee effect
rsk_nonstat_nolevee <- logistic((0.015*wl_nonstat_samp)-11, 0.8, 0.6) # hypothetical risk pdf with non-stationary with uncertainty pdf and depth-damage function without levee effect
rsk_nonstat_levee <- logistic((0.015*wl_nonstat_samp)-11, 0.8, 0.6) * LEV# hypothetical risk pdf with non-stationary with uncertainty pdf and levee effect
dat_stat_nolevee <- data.frame(wl=wl_stat_samp, dmg=rsk_stat_nolevee, group='stat_nolevee')
dat_nonstat_nolevee <- data.frame(wl=wl_nonstat_samp, dmg=rsk_nonstat_nolevee, group='nonstat_nolevee')
dat_nonstat_levee <- data.frame(wl=wl_nonstat_samp, dmg=rsk_nonstat_levee, group='nonstat_levee')
dat_all <- rbind(dat_stat_nolevee, dat_nonstat_nolevee, dat_nonstat_levee)
dat_dmg_nolevee <- data.frame(wl=WL, dmg=dmg_nolevee, group="nolevee")
dat_dmg_levee <- data.frame(wl=WL, dmg=dmg_levee, group="levee")
dat_dmg_all <- rbind(dat_dmg_nolevee, dat_dmg_levee)
# diagnostic plot
dat_dmg <- data.frame(wl=WL, dmg=dmg_nolevee[WL])
p <- ggplot() + geom_line(dat=dat_dmg, aes(x=wl, y=dmg)) +
geom_point(dat=dat_stat_nolevee, aes(x=wl, y=dmg), col='red') +
geom_vline(aes(xintercept=WLbest), linetype='dashed') +
geom_hline(aes(yintercept=rsk_nounc_nolevee), linetype='dashed', col='red') +
theme_classic() +
scale_x_continuous(limits=c(0, 1000), expand=c(0, 0)) +
scale_y_continuous(expand=c(0, 0))
p1 <- ggMarginal(p, type='histogram', xparams=list(bins=49), yparams=list(bins=49, fill='red'))
# rebuild original plot
# hazard (water levels)
dens_wl <- density(wl_stat_samp)
a<-ggplot(dat_all[dat_all$group %in% c('stat_nolevee', 'nonstat_nolevee'),], aes(x=wl,group=group)) +
geom_density(aes(color=group),size=1.5)+
geom_segment(aes(x = WLbest, xend=WLbest, y=0, yend=max(dens_wl$y)), size=1, linetype="solid", color="black") + #hypothetical best guess stationary water levels
scale_colour_manual(name = '',
values =c(nonstat_nolevee='darkblue',stat_nolevee='cornflowerblue'))+
scale_x_continuous("Water Levels", expand = c(0, 0), limits=c(0, 1100)) +
scale_y_continuous("Probability Density", expand = c(0, 0)) +
annotate(x=580,y=0.006, geom="text",
label="Neglecting\nclimate change\nand uncertainty",
color="black",size=6,lineheight = .75,hjust="left")+
annotate(x=725,y=0.004,geom="text",
label="Considering\nclimate change\nand uncertainty",
color="darkblue",size=6,lineheight = .75,hjust="left")+
annotate(x=450,y=0.0055,geom="text",
label="Neglecting\nclimate change\nconsidering\nuncertainty",
color="cornflowerblue",size=6,lineheight = .75,hjust="right")+
theme_classic()+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_text(size=18, face="bold"),
axis.title.y = element_text(size=18, face="bold"),
legend.text=element_text(size=18),
legend.position = "none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_line(arrow = arrow(angle = 15, length = unit(0.2, "inches"),type = "closed"))) +
coord_cartesian(ylim=c(0, 0.007))
# Plot b - Vulnerability
b<-ggplot(dat_dmg_all,aes(x=wl, y=dmg, group=group))+
geom_line(aes(color=group),size=1.5)+
scale_colour_manual(name = '',
values =c(nolevee='darkkhaki',levee='darkgreen'))+
scale_x_continuous("Water Levels", expand = c(0, 0), limits = c(0, 1100)) +
scale_y_continuous("Damages", expand = c(0, 0), limits = c(0, 1.1*max(dat_dmg_levee$dmg))) +
annotate(x=525,y=0.6*max(dat_dmg_levee$dmg), geom="text",
label="Considering\nlevee effect", color="darkgreen",
size=6,lineheight = .75)+
annotate(x=775,y=0.25*max(dat_dmg_levee$dmg), geom="text",
label="Neglecting\nlevee effect", color="darkkhaki",
size=6,lineheight = .75)+
theme_classic()+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_text(size=18, face="bold"),
axis.title.y = element_text(size=18, face="bold"),
legend.text=element_text(size=18),
legend.position = "none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_line(arrow = arrow(angle = 15, length = unit(0.2, "inches"),type = "closed")))
# Plot c - Risk
c<-ggplot(dat_all,aes(x=dmg, group=group))+
geom_density(aes(color=group),size=1.5)+
geom_segment(aes(x=rsk_nounc_nolevee, xend=rsk_nounc_nolevee, y=0, yend=9),size=1,linetype="solid", color="black")+ #hypothetical best guess stationary water levels
annotate(x=mean(rsk_nonstat_levee),y=9, geom="point",size=4,color="darkred")+
annotate(x=mean(rsk_nonstat_nolevee),y=9, geom="point",size=4,color="orangered1")+
annotate(x=mean(rsk_stat_nolevee),y=9, geom="point",size=4,color="orange")+
scale_colour_manual(name = '',
values =c(nonstat_levee='darkred',nonstat_nolevee='orangered1',stat_nolevee='orange')) +
scale_x_continuous("Damages", expand = c(0, 0), limits = c(0, 1.4)) +
scale_y_continuous("Probability Density", expand = c(0, 0), limits = c(0, 9.5)) +
geom_segment(x=0.18,y=8.5,xend = 0.18,yend = 9,
size=0.5,arrow = arrow(angle = 15, length = unit(0.1, "inches")))+
annotate(x=0.1,y=7.5, geom="label", label="Expected\nvalues",
size=6,hjust="center",lineheight = .75,fill="lightgray")+
annotate(x=0.28,y=7.5, geom="text",
label="Neglecting all",
color="black",size=6,hjust="right",lineheight = .75)+
annotate(x=1.2,y=0.9, geom="text",
label="Considering all",
hjust="left",color="darkred",size=6,lineheight = .75)+
geom_segment(x=1.2,y=0.85,xend = 1.2,yend = 0.5,
size=0.5,color="darkred",arrow = arrow(angle = 15, length = unit(0.1, "inches")))+
annotate(x=0.95,y=1.5, geom="text",
label="Neglecting levee effect",
hjust="left",color="orangered1",size=6,lineheight = .75)+
geom_segment(x=0.95,y=1.45,xend = 0.95,yend = 0.48,
size=0.5,color="orangered1",arrow = arrow(angle = 15, length = unit(0.1, "inches")))+
annotate(x=0.45,y=2.61, geom="text",
label="Neglecting climate change\nand levee effect",
hjust="left",color="orange",size=6,lineheight = .75)+
geom_segment(x=0.37,y=3.1,xend = 0.29,yend = 3.1,
size=0.5,color="orange",arrow = arrow(angle = 15, length = unit(0.1, "inches")))+
theme_classic()+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_text(size=18, face="bold"),
axis.title.y = element_text(size=18, face="bold"),
legend.text=element_text(size=18),
legend.position = "none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.line = element_line(arrow = arrow(angle = 15, length = unit(0.2, "inches"),
type = "closed")))+
coord_flip()
# Organizing plots
figure1 <- ggarrange(b,c,a,
labels = c("b) Exposure Effect"," c) Risk"," a) Hazard"),
font.label = list(size = 18),
vjust =1.5, hjust =-.3,
ncol = 2, nrow = 2)
# Coordinates of the start and end points of the leader line
x1=0.254; y1=0.40
x2=0.53; y2=0.615
# Adding leader lines and arrowheads
figure<-figure1+geom_segment(aes(x=x1,xend=x1,y=y1,yend=y2),size=1,linetype="dotted")+
geom_segment(aes(x=x1,xend=x1,y=y2-0.01,yend=y2),arrow = arrow(angle = 15, length = unit(0.2, "inches"),type="closed"))+
geom_segment(aes(x=x1,xend=x2,y=y2,yend=y2),size=1,linetype="dotted")+
geom_segment(aes(x=x2-0.01,xend=x2,y=y2,yend=y2),arrow = arrow(angle = 15, length = unit(0.2, "inches"),type="closed"))
# Saving a JPG and PDF file of the plot
ggsave("Risk_Interactions.jpg",width = 11, height = 8.5, units = c("in"),dpi = 600)
ggsave("Risk_Interactions.pdf",width = 11, height = 8.5, units = c("in"),dpi = 600)
# Time to clean up!
rm(list=ls())