-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathriverdischarge.Rmd
229 lines (161 loc) · 10.9 KB
/
riverdischarge.Rmd
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
output: word_document
---
A percentile is a value on a scale of one hundred that indicates the percent of a distribution that is equal to or below it. For example, on the map of daily streamflow conditions a river discharge at the 90th percentile is equal to or greater than 90 percent of the discharge values recorded on this day of the year during all years that measurements have been made. In general,a percentile greater than 75 is considered above normal, a percentile between 25 and 75 is considered normal, and a percentile less than 25 is considered below normal.
These data are retrieved via the `waterData` package in R made available by U.S. Geological Survey (USGS). These data are collected at the USGS 02323500 Suwannee River station near Wilcox, Florida. This site is located in Levy County, Florida (latitude 29.58968 and longitude -82.93651 in degrees).
```{r rd_options setup, include=FALSE, warning=FALSE, message=FALSE, comment=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("tidyverse")
library("lubridate")
library("waterData")
library("scales")
library('ggpubr')
```
```{r, include= FALSE, warning=FALSE, message=FALSE, comment=FALSE}
station = '02323500'
stinfo = siteInfo(station)
# Load data and dynamically check if data needs to be updated
dis <- read_rds("data/dis.rds")
if (max(dis$dates) < (Sys.Date() - 5)) {
sdate <- max(dis$dates) + 1
newdis <- importDVs(staid = station, code = '00060', stat = '00003', sdate= as.character(sdate))
dis <- bind_rows(dis, newdis) %>%
distinct() # In case there's repeated rows due to code failure
write_rds(dis, "data/dis.rds")
}
dis <- read_rds("data/dis.rds")
if (max(dis$dates) < (Sys.Date() - 5)) {
sdate <- max(dis$dates) + 1
newdis <- importDVs(staid = station, code = '00060', stat = '00003', sdate= as.character(sdate))
dis <- bind_rows(dis, newdis) %>%
distinct() # In case there's repeated rows due to code failure
write_rds(dis, "data/dis.rds")
}
# Since dis$dates is already Date object, no action requires for dates column
# Remove leap days
dis_noleap <- dis %>%
filter(!(month(dates) == 2 & day(dates) == 29))
# Calculate 0%, 25%, 50%, 75% and 100% quantile for each day
# dplyr and tidyr involve here
dis_quant <- dis_noleap %>%
mutate(md = strftime(dates, format = "%m-%d")) %>%
group_by(md) %>%
summarise(quan0 = quantile(val, 0, na.rm=TRUE),
quan10 = quantile(val, 0.10, na.rm=TRUE),
quan25 = quantile(val, 0.25, na.rm=TRUE),
quan75 = quantile(val, 0.75, na.rm=TRUE),
quan90 = quantile(val, 0.90, na.rm=TRUE),
quan100 = quantile(val, 1, na.rm=TRUE)) %>%
gather("quantile", "val", -md)
# Remove the "quan" and set the quantile column to factor of 5 levels
# Note that the levels are on descending order because this force ggplot
# to plot quantile 100, then overlay quantile 75 on top of it, so on and
# so forth, i.e. quantile 100 won't cover other quantiles up.
dis_quant$quantile <- str_remove(dis_quant$quantile, "quan") %>%
factor(levels = c("100", "90", "75", "25", "10", "0"))
minValues <- dis_quant$val[dis_quant$quantile == '0']
dis_quant$min <- rep(minValues, times = 6)
dis_quant1 <- subset(dis_quant, dis_quant$quantile != '0')
# To use cowplot, each plot needs to be created separely. Facet wrap can creat a publication label at the top left
cbPalette <- c("mediumpurple3", "darkslategray2", "palegreen2", "sandybrown", "indianred4")
```
```{r, echo= FALSE, warning=FALSE, message=FALSE, comment=FALSE, fig.height= 30, fig.width= 20}
plot_list = list()
for (i in 1:72) { # Loop over loop.vector
# Year of interest, keep this at the current year
yoi = i + 1949
# Add year to dis_quant's date for plotting purpose
dis_quant2 <- dis_quant1 %>%
mutate(dates = paste(yoi, md, sep="-") %>% as.Date)
dis_yoi <- dis_noleap %>%
filter(year(dates) == yoi)
rd_plot<-ggplot(dis_yoi, aes(x=dates, y=val)) +
xlab("Month")+
ylab("\n River Discharge \n (ft^3)") +
labs(title= yoi ,fill= "Quantile") +
geom_ribbon(data = dis_quant2, aes(x=dates, ymax=val, ymin=min, fill=quantile)) +
geom_line(size=1.1) +
scale_fill_manual(values=cbPalette) +
scale_x_date(labels = date_format("%b"))+
theme_minimal() +
theme(legend.position = "right", panel.border = element_rect(colour = "black", fill=NA, size=1))
plot_list[[i]]= rd_plot
}
ggarrange(plotlist=plot_list, common.legend = FALSE, ncol = 5, nrow = 15)
```
**Figure 1.** River discharge (by convention CFS, y axis) from the USGS Wilcox, Florida gauge (USGS 02322500) for the years 2005-2021 (solid black line). The areas of color represent percentiles where each percentile is a value on a scale of one hundred that indicates the percent of a distribution that is equal to or below it. For example, on the map of daily streamflow conditions a river discharge at the 90th percentile is equal to or greater than 90 percent of the discharge values recorded on this day of the year during all years that measurements have been made. In general, a percentile greater than 75 is considered above normal, a percentile between 25 and 75 is considered normal, and a percentile less than 25 is considered below normal. The percentiles are based on the period of record for this gauge station.
```{r, echo= FALSE, warning=FALSE, message=FALSE, comment=FALSE, fig.height=20, fig.width= 10}
plot_list = list()
for (i in 1:17) { # Loop over loop.vector
# Year of interest, keep this at the current year
yoi = i + 2004
# Add year to dis_quant's date for plotting purpose
dis_quant2 <- dis_quant1 %>%
mutate(dates = paste(yoi, md, sep="-") %>% as.Date)
dis_yoi <- dis_noleap %>%
filter(year(dates) == yoi)
rd_plot<-ggplot(dis_yoi, aes(x=dates, y=val)) +
xlab("Month")+
ylab("\n River Discharge \n (ft^3)") +
labs(title= yoi ,fill= "Quantile") +
geom_ribbon(data = dis_quant2, aes(x=dates, ymax=val, ymin=min, fill=quantile)) +
geom_line(size=1.1) +
scale_fill_manual(values=cbPalette) +
scale_x_date(labels = date_format("%b"))+
theme_minimal() +
theme(legend.position = "right", panel.border = element_rect(colour = "black", fill=NA, size=1))
plot_list[[i]]= rd_plot
}
ggarrange(plotlist=plot_list, common.legend = FALSE, ncol = 2, nrow = 9)
```
**Figure 2.** River discharge (by convention CFS, y axis) from the USGS Wilcox, Florida gauge (USGS 02322500) for the years 2005-2021 (solid black line). The areas of color represent percentiles where each percentile is a value on a scale of one hundred that indicates the percent of a distribution that is equal to or below it. For example, on the map of daily streamflow conditions a river discharge at the 90th percentile is equal to or greater than 90 percent of the discharge values recorded on this day of the year during all years that measurements have been made. In general, a percentile greater than 75 is considered above normal, a percentile between 25 and 75 is considered normal, and a percentile less than 25 is considered below normal. The percentiles are based on the period of record for this gauge station.
```{r, echo= FALSE, warning=FALSE, message=FALSE, comment=FALSE, fig.height=20, fig.width= 15}
plot_list = list()
for (i in 1:8) { # Loop over loop.vector
# Year of interest, keep this at the current year
yoi = i + 2004
# Add year to dis_quant's date for plotting purpose
dis_quant2 <- dis_quant1 %>%
mutate(dates = paste(yoi, md, sep="-") %>% as.Date)
dis_yoi <- dis_noleap %>%
filter(year(dates) == yoi)
rd_plot<-ggplot(dis_yoi, aes(x=dates, y=val)) +
xlab("Month")+
ylab("\n River Discharge \n (ft^3)") +
labs(title= yoi ,fill= "Quantile") +
geom_ribbon(data = dis_quant2, aes(x=dates, ymax=val, ymin=min, fill=quantile)) +
geom_line(size=1.1) +
scale_fill_manual(values=cbPalette) +
scale_x_date(labels = date_format("%b"))+
theme_minimal() +
theme(legend.position = "right", panel.border = element_rect(colour = "black", fill=NA, size=1))
plot_list[[i]]= rd_plot
}
ggarrange(plotlist=plot_list, common.legend = FALSE, ncol = 2, nrow = 4)
```
**Figure 3.** River discharge (by convention CFS, y axis) from the USGS Wilcox, Florida gauge (USGS 02322500) for the years 2005-2012 (solid black line) representing the years preceding observed extreme low discharge conditions 2010-2012. The areas of color represent percentiles where each percentile is a value on a scale of one hundred that indicates the percent of a distribution that is equal to or below it. For example, on the map of daily streamflow conditions a river discharge at the 90th percentile is equal to or greater than 90 percent of the discharge values recorded on this day of the year during all years that measurements have been made. In general, a percentile greater than 75 is considered above normal, a percentile between 25 and 75 is considered normal, and a percentile less than 25 is considered below normal. The percentiles are based on the period of record for this gauge station.
```{r, echo= FALSE, warning=FALSE, message=FALSE, comment=FALSE, fig.height=12, fig.width= 10}
plot_list = list()
for (i in 1:9) { # Loop over loop.vector
# Year of interest, keep this at the current year
yoi = i + 2012
# Add year to dis_quant's date for plotting purpose
dis_quant2 <- dis_quant1 %>%
mutate(dates = paste(yoi, md, sep="-") %>% as.Date)
dis_yoi <- dis_noleap %>%
filter(year(dates) == yoi)
rd_plot<-ggplot(dis_yoi, aes(x=dates, y=val)) +
xlab("Month")+
ylab("\n River Discharge \n (ft^3)") +
labs(title= yoi ,fill= "Quantile") +
geom_ribbon(data = dis_quant2, aes(x=dates, ymax=val, ymin=min, fill=quantile)) +
geom_line(size=1.1) +
scale_fill_manual(values=cbPalette) +
scale_x_date(labels = date_format("%b"))+
theme_minimal() +
theme(legend.position = "right", panel.border = element_rect(colour = "black", fill=NA, size=1))
plot_list[[i]]= rd_plot
}
ggarrange(plotlist=plot_list, common.legend = FALSE, ncol = 2, nrow = 5)
```
**Figure 4.** River discharge (by convention CFS, y axis) from the USGS Wilcox, Florida gauge (USGS 02322500) for the years 2013-2021 (solid black line) representing the years since 2010-2012 low flow conditions including the initiation of the Lone Cabbage Reef restoration project. The areas of color represent percentiles where each percentile is a value on a scale of one hundred that indicates the percent of a distribution that is equal to or below it. For example, on the map of daily streamflow conditions a river discharge at the 90th percentile is equal to or greater than 90 percent of the discharge values recorded on this day of the year during all years that measurements have been made. In general, a percentile greater than 75 is considered above normal, a percentile between 25 and 75 is considered normal, and a percentile less than 25 is considered below normal. The percentiles are based on the period of record for this gauge station.