-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSite_Spec.R
120 lines (88 loc) · 4.33 KB
/
Site_Spec.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
##So, you'll want to change the function variable from wbid to site and then in the code inside
##filter() you'll change it to site_acronym == site which will then make your variable input
##whatever site you want to select using the inputs from the site acronym column.
## have to use sitez because site plots blank because site is already a column in data set!
sites <- function(param, sitez, axis_title) {
# param - use component_short parameter name in quotes
# site - use site acronymns names in the site_acronym column, in quotes
# axis_title - use axis title value from 00_vis_custom.R, no quotes, or new title in quotes.
p <- dat2 %>%
dplyr::filter(component_short == param &
end == "N" &
site_acronym == sitez) %>%
ggplot(aes(x = date_sampled, y = result, color = site_friendly)) +
geom_point(size = 3) +
geom_line(size = 1) +
scale_colour_manual(name = "Site", values = sitecolours) +
cowplot::theme_cowplot() +
scale_y_continuous(expand = c(0,0)) +
scale_x_datetime(date_breaks = '1 month', date_minor_breaks = '2 weeks', date_labels='%b-%y') +
theme(axis.text.x = element_text(angle = 90, vjust=0.3, size=12, color='black')) +
labs(y = axis_title,
x = "",
title = paste(param),
subtitle = paste(sitez))
p
}
sites('TN', 'MK', 'Total Nitrogen')
--------------- site specific with threshold ------------------------
sites_thres <- function(param, sitez, threshold, axis_title) {
# param - use component_short parameter name in quotes
# site - use site acronymns names in the site_acronym column, in quotes
# axis_title - use axis title value from 00_vis_custom.R, no quotes, or new title in quotes.
p <- dat2 %>%
dplyr::filter(component_short == param &
end == "N" &
site_acronym == sitez) %>%
ggplot(aes(x = date_sampled, y = result, color = site_friendly)) +
geom_point(size = 3) +
geom_line(size = 1) +
geom_hline(yintercept = threshold, linetype = 'longdash', color = 'gray18', size = 1.5) +
scale_colour_manual(name = "Site", values = sitecolours) +
cowplot::theme_cowplot() +
scale_y_continuous(expand = c(0,0)) +
scale_x_datetime(date_breaks = '1 year', date_labels='%Y') +
theme(axis.text.x = element_text(angle = 90, vjust=0.3, size=12, color='black')) +
labs(y = axis_title,
x = "",
title = paste(param),
subtitle = paste0("Advisory = ", threshold))
p
}
sites_thres("FECCOL", 'GL2', 71, "Feccolcoliform")
sites_thres("DO_P", "LM", 42, "Dissolved Oxygen %")
--------------- site specific with lm or stats ---------------
##
## have to use sitez because site plots blank because site is already a column in data set!
##had to change formatting of DATE so R could read it right
dat2 <- dat2 %>%
mutate(DATE = lubridate::as_date(date_sampled))
sites_stat <- function(param, sitez, axis_title) {
# param - use component_short parameter name in quotes
# site - use site acronymns names in the site_acronym column, in quotes
# axis_title - use axis title value from 00_vis_custom.R, no quotes, or new title in quotes.
p <- dat2 %>%
dplyr::filter(component_short == param &
end == "N" &
site_acronym == sitez) %>%
ggplot(aes(x = DATE, y = result, color = site_friendly)) +
scale_x_date(
limits = as.Date(c("2017-07-01", "2021-07-01")),
date_breaks = "1 year", date_labels = "%Y") +
geom_point(size = 3) +
geom_line(size = 1) +
geom_smooth(method = "lm", color = "black") +
ggpubr::stat_regline_equation(label.y = 15, aes(label = ..rr.label..))+
scale_colour_manual(name = "Site", values = sitecolours) +
cowplot::theme_cowplot() +
scale_y_continuous(expand = c(0,0)) +
#scale_x_datetime(date_labels='%Y', date_breaks = '1 year', limits = c("2017-07-20" - "2021-09-07"))+
#scale_x_datetime(date_breaks = '1 month', date_minor_breaks = '2 weeks', date_labels='%b-%y') +
theme(axis.text.x = element_text(vjust=0.3, size=12, color='black')) +
labs(y = axis_title,
x = "",
title = paste(param),
subtitle = paste(sitez))
p
}
sites_stat("CHLA_C", 'GR', "Chlora")