-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabiotic_graphing.R
412 lines (347 loc) · 18.5 KB
/
abiotic_graphing.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
### ABIOTIC GRAPHING
## Load packages ---------------------------------------------------------------
if (!require(tidyverse, quietly = TRUE)) {
install.packages("tidyverse")
library(tidyverse)}
if (!require(readxl, quietly = TRUE)) {
install.packages("readxl")
library(readxl)}
if (!require(lubridate, quietly = TRUE)) {
install.packages("lubridate")
library(lubridate)}
## Import data -----------------------------------------------------------------
# PWQMN data
ammonium <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Ammonium") # ammonium
View(ammonium)
chloride <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Chloride") # chloride
View(chloride)
conductivity <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Conductivity") # conductivity
View(conductivity)
dissolved_oxygen <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Dissolved Oxygen") # dissolved oxygen
View(dissolved_oxygen)
nitrate <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Nitrate") # nitrate
View(nitrate)
nitrite <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Nitrite") # nitrite
View(nitrite)
ph <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "pH") # pH
View(ph)
phosphate <- read_excel("./data/water_quality/PWQMN_Mill_Creek_Data.xlsx", sheet = "Phosphate") # phosphate
View(phosphate)
# Most extreme years
air_temp_summarized <- read.csv("data/air_temp/CSM_summarized_air_temp.csv") # air temperature - all years summarized
View(air_temp_summarized)
ABF_water_temp_summarized <- read.csv("data/water_temp/ABF_summarized_water_temp.csv") # Aberfoyle water temperature - all years summarized
View(ABF_water_temp_summarized)
SR10_water_temp_summarized <- read.csv("data/water_temp/SR10_summarized_water_temp.csv") # Side Road 10 water temperature - all years summarized
View(SR10_water_temp_summarized)
precip_summarized <- read.csv("data/precipitation/CSM_summarized_precip.csv") # precipitation - all years summarized
View(precip_summarized)
# Rangers Restoration data
ranger_activities <- read.csv("data/Ranger_restoration_activities.csv", header=TRUE) # restoration activities by type
View(ranger_activities)
ranger_sites <- read.csv("data/Ranger_work_sites.csv", header=TRUE) # restoration work sites
View(ranger_sites)
## Data prep -------------------------------------------------------------------
# PWQMN data
ammonium$Collection_Date <- as.Date(ammonium$`Collection Timestamp`)
View(ammonium)
chloride$Collection_Date <- as.Date(chloride$`Collection Timestamp`)
View(chloride)
conductivity$Collection_Date <- as.Date(conductivity$`Collection Timestamp`)
View(conductivity)
dissolved_oxygen$Collection_Date <- as.Date(dissolved_oxygen$`Collection Timestamp`)
View(dissolved_oxygen)
nitrate$Collection_Date <- as.Date(nitrate$`Collection Timestamp`)
View(nitrate)
nitrite$Collection_Date <- as.Date(nitrite$`Collection Timestamp`)
View(nitrite)
phosphate$Collection_Date <- as.Date(phosphate$`Collection Timestamp`)
View(phosphate)
ph$Collection_Date <- as.Date(ph$`Collection Timestamp`)
View(ph)
# Most extreme years
# Air temperature
air_temp_summarized$Month <- month.abb[air_temp_summarized$Month] # give months abbreviated names
air_temp_summarized$Month <- factor(air_temp_summarized$Month, levels = month.abb) # convert month to a factor
View(air_temp_summarized)
air_temp_2002 <- subset(air_temp_summarized, Year == 2002) # select 2002 data
air_temp_2005 <- subset(air_temp_summarized, Year == 2005) # select 2005 data
air_temp_2009 <- subset(air_temp_summarized, Year == 2009) # select 2009 data
air_temp_2011 <- subset(air_temp_summarized, Year == 2011) # select 2011 data
air_temp_2012 <- subset(air_temp_summarized, Year == 2012) # select 2012 data
air_temp_2014 <- subset(air_temp_summarized, Year == 2014) # select 2014 data
air_temp_2015 <- subset(air_temp_summarized, Year == 2015) # select 2015 data
air_temp_2020 <- subset(air_temp_summarized, Year == 2020) # select 2020 data
air_temp_all_years <- bind_rows(air_temp_2002, air_temp_2005, air_temp_2009, air_temp_2011, air_temp_2012, air_temp_2014, air_temp_2015, air_temp_2020)
View(air_temp_all_years)
# Water temperature - Aberfoyle station
ABF_water_temp_summarized$Month <- month.abb[ABF_water_temp_summarized$Month] # give months abbreviated names
ABF_water_temp_summarized$Month <- factor(ABF_water_temp_summarized$Month, levels = month.abb) # convert month to a factor
View(ABF_water_temp_summarized)
ABF_high_water_temp_2005 <- subset(ABF_water_temp_summarized, Year == 2005) # select 2005 data - high temp
ABF_high_water_temp_2006 <- subset(ABF_water_temp_summarized, Year == 2006) # select 2006 data - high temp
ABF_high_water_temp_2011 <- subset(ABF_water_temp_summarized, Year == 2011) # select 2011 data - high temp
ABF_high_water_temp_2016 <- subset(ABF_water_temp_summarized, Year == 2016) # select 2016 data - high temp
ABF_high_water_temp_2019 <- subset(ABF_water_temp_summarized, Year == 2019) # select 2019 data - high temp
ABF_high_water_temp_all_years <- bind_rows(ABF_high_water_temp_2005, ABF_high_water_temp_2006, ABF_high_water_temp_2011, ABF_high_water_temp_2016, ABF_high_water_temp_2019)
View(ABF_high_water_temp_all_years)
ABF_low_water_temp_2005 <- subset(ABF_water_temp_summarized, Year == 2005) # select 2005 data - low temp
ABF_low_water_temp_2008 <- subset(ABF_water_temp_summarized, Year == 2008) # select 2008 data - low temp
ABF_low_water_temp_2009 <- subset(ABF_water_temp_summarized, Year == 2009) # select 2009 data - low temp
ABF_low_water_temp_2014 <- subset(ABF_water_temp_summarized, Year == 2014) # select 2014 data - low temp
ABF_low_water_temp_2019 <- subset(ABF_water_temp_summarized, Year == 2019) # select 2019 data - low temp
ABF_low_water_temp_all_years <- bind_rows(ABF_low_water_temp_2005, ABF_low_water_temp_2008, ABF_low_water_temp_2009, ABF_low_water_temp_2014, ABF_low_water_temp_2019)
View(ABF_low_water_temp_all_years)
# Water temperature - Side Road 10 station
SR10_water_temp_summarized$Month <- month.abb[SR10_water_temp_summarized$Month] # give months abbreviated names
SR10_water_temp_summarized$Month <- factor(SR10_water_temp_summarized$Month, levels = month.abb) # convert month to a factor
View(SR10_water_temp_summarized)
SR10_high_water_temp_2001 <- subset(SR10_water_temp_summarized, Year == 2001) # select 2001 data - high temp
SR10_high_water_temp_2002 <- subset(SR10_water_temp_summarized, Year == 2002) # select 2002 data - high temp
SR10_high_water_temp_2012 <- subset(SR10_water_temp_summarized, Year == 2012) # select 2012 data - high temp
SR10_high_water_temp_2023 <- subset(SR10_water_temp_summarized, Year == 2023) # select 2023 data - high temp
SR10_high_water_temp_all_years <- bind_rows(SR10_high_water_temp_2001, SR10_high_water_temp_2002, SR10_high_water_temp_2012, SR10_high_water_temp_2023)
View(SR10_high_water_temp_all_years)
SR10_low_water_temp_2003 <- subset(SR10_water_temp_summarized, Year == 2003) # select 2003 data - low temp
SR10_low_water_temp_2018 <- subset(SR10_water_temp_summarized, Year == 2018) # select 2018 data - low temp
SR10_low_water_temp_2019 <- subset(SR10_water_temp_summarized, Year == 2019) # select 2019 data - low temp
SR10_low_water_temp_all_years <- bind_rows(SR10_low_water_temp_2003, SR10_low_water_temp_2018, SR10_low_water_temp_2019)
View(SR10_low_water_temp_all_years)
# Precipitation
precip_summarized$Month <- month.abb[precip_summarized$Month] # give months abbreviated names
precip_summarized$Month <- factor(precip_summarized$Month, levels = month.abb) # convert month to a factor
View(precip_summarized)
high_precip_2006 <- subset(precip_summarized, Year == 2006) # select 2006 data - high precip year
high_precip_2008 <- subset(precip_summarized, Year == 2008) # select 2008 data - high precip year
high_precip_2016 <- subset(precip_summarized, Year == 2016) # select 2016 data - high precip year
high_precip_2019 <- subset(precip_summarized, Year == 2019) # select 2019 data - high precip year
high_precip_2023 <- subset(precip_summarized, Year == 2023) # select 2023 data - high precip year
high_precip_years <- bind_rows(high_precip_2006, high_precip_2008, high_precip_2016, high_precip_2019, high_precip_2023)
View(high_precip_years)
low_precip_2007 <- subset(precip_summarized, Year == 2007) # select 2007 data - low precip year
low_precip_2011 <- subset(precip_summarized, Year == 2011) # select 2011 data - low precip year
low_precip_2015 <- subset(precip_summarized, Year == 2015) # select 2015 data - low precip year
low_precip_2017 <- subset(precip_summarized, Year == 2017) # select 2017 data - low precip year
low_precip_2022 <- subset(precip_summarized, Year == 2022) # select 2022 data - low precip year
low_precip_years <- bind_rows(low_precip_2007, low_precip_2011, low_precip_2015, low_precip_2017, low_precip_2022)
View(low_precip_years)
# Rangers Restoration data
# Restoration methods
years_reported_activities <- ranger_activities %>%
distinct(Year,Restoration.Work.Performed) %>%
group_by(Restoration.Work.Performed)%>%
summarise(count=n())
years_reported_activities$Restoration.Work.Performed <- as.factor(years_reported_activities$Restoration.Work.Performed)
years_reported_activities$Restoration.Work.Performed <- factor(years_reported_activities$Restoration.Work.Performed, levels = years_reported_activities$Restoration.Work.Performed[order(years_reported_activities$count, decreasing = TRUE)])
#Restoration sites
years_reported_sites<-ranger_sites %>%
distinct(Year,Location) %>%
group_by(Location)%>%
summarise(count=n())
years_reported_sites$Location <- as.factor(years_reported_sites$Location)
years_reported_sites$Location <- factor(years_reported_sites$Location, levels = years_reported_sites$Location[order(years_reported_sites$count, decreasing = TRUE)])
# PWQMN graphs -----------------------------------------------------------------
ammonium %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Ammonium") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
chloride %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Chloride") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
conductivity %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Conductivity") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
dissolved_oxygen %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Dissolved oxygen") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
nitrate %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Nitrate") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
nitrite %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Nitrite") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
phosphate %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("Phosphate") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
ph %>%
ggplot(aes(Collection_Date, Result)) +
geom_point(aes(colour = Units, shape = Method)) +
geom_line() +
theme_minimal() +
xlab("Date") +
ylab("Result") +
ggtitle("pH") +
scale_x_date(date_breaks = "2 years", date_labels = "%Y") +
theme(plot.title = element_text(hjust = 0.5))
# Most extreme years graphs ----------------------------------------------------
# Air temperature
ggplot(air_temp_all_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", nrow=4, ncol=2) +
geom_point(aes(y = Average, color = "Average"), size = 3, shape = 18) +
geom_point(aes(y = Minimum, color = "Minimum"), size = 1, shape = 3) +
geom_point(aes(y = Maximum, color = "Maximum"), size = 1, shape = 0) +
labs(x = "Month",
y = "Monthly mean air temperature (C)",
color = "Legend") +
scale_color_manual(values = colors) +
ylim(-30,40) +
theme_minimal() +
theme(panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
# Water temperature - Aberfoyle station
ggplot(ABF_high_water_temp_all_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", nrow=3, ncol=2) +
geom_point(aes(y = Average, color = "Average"), size = 3, shape = 18) +
geom_point(aes(y = Minimum, color = "Minimum"), size = 1, shape = 3) +
geom_point(aes(y = Maximum, color = "Maximum"), size = 1, shape = 0) +
labs(x = "Month",
y = "Water temperature (C)",
color = "Legend") +
scale_color_manual(values = colors) +
ggtitle("Aberfoyle, high temperature years") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5), panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
ggplot(ABF_low_water_temp_all_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", nrow=3, ncol=2) +
geom_point(aes(y = Average, color = "Average"), size = 3, shape = 18) +
geom_point(aes(y = Minimum, color = "Minimum"), size = 1, shape = 3) +
geom_point(aes(y = Maximum, color = "Maximum"), size = 1, shape = 0) +
labs(x = "Month",
y = "Water temperature (C)",
color = "Legend") +
scale_color_manual(values = colors) +
ggtitle("Aberfoyle, low temperature years") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5), panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
# Water temperature - Side Road 10 station
ggplot(SR10_high_water_temp_all_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", nrow=3, ncol=2) +
geom_point(aes(y = Average, color = "Average"), size = 3, shape = 18) +
geom_point(aes(y = Minimum, color = "Minimum"), size = 1, shape = 3) +
geom_point(aes(y = Maximum, color = "Maximum"), size = 1, shape = 0) +
labs(x = "Month",
y = "Water temperature (C)",
color = "Legend") +
scale_color_manual(values = colors) +
ggtitle("Side Road 10, high temperature years") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5), panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
ggplot(SR10_low_water_temp_all_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", nrow=3, ncol=2) +
geom_point(aes(y = Average, color = "Average"), size = 3, shape = 18) +
geom_point(aes(y = Minimum, color = "Minimum"), size = 1, shape = 3) +
geom_point(aes(y = Maximum, color = "Maximum"), size = 1, shape = 0) +
labs(x = "Month",
y = "Water temperature (C)",
color = "Legend") +
scale_color_manual(values = colors) +
ggtitle("Side Road 10, low temperature years") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5), panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
# Precipitation - high years
ggplot(high_precip_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", ncol = 2) +
geom_point(aes(y = Total, color = "Total"), size = 3, shape = 18) +
labs(x = "Month",
y = "Total precipitation (mm)",
colour = "Legend") +
scale_color_manual(values = colours) +
ylim(0,250) +
ggtitle("High precipitation years") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5), panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
# Precipitation - low years
ggplot(low_precip_years, aes(x = Month)) +
facet_wrap(~Year, scales = "free", ncol=2) +
geom_point(aes(y = Total, color = "Total"), size = 3, shape = 18) +
labs(x = "Month",
y = "Total precipitation (mm)",
colour = "Legend") +
scale_color_manual(values = colours) +
ylim(0,250) +
ggtitle("Low precipitation years") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5), panel.grid.minor = element_line(color = "grey",
linewidth = 0.1,
linetype = 2))
# Rangers restoration graphs ---------------------------------------------------
palette <- hcl.colors(18, palette = "Set2") # define colour palette
# Restoration methods
ggplot(years_reported_activities, aes(x = Restoration.Work.Performed, y = count, fill = Restoration.Work.Performed)) +
geom_bar(stat = "identity", color = "black") +
scale_fill_manual(values=palette) +
labs(x = "Type of Restoration Work Reported",
y = "Number of Years Reported",
fill = "Restoration Work Reported") +
theme_minimal() +
scale_y_continuous(breaks = c(0,2,4,6,8,10,12,14,16,18,20)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1), legend.position = "none")
# Restoration sites
ggplot(years_reported_sites, aes(x = Location, y = count, fill = Location)) +
geom_bar(stat = "identity", color="black") +
scale_fill_manual(values = palette) +
labs(x = "Location of Restoration Work",
y = "Number of Years Reported",
fill = "Restoration Work Reported") +
theme_minimal() +
scale_y_continuous(breaks = c(0,2,4,6,8,10,12,14)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1), legend.position = "none")