-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadditional_practice_20210819.R
More file actions
134 lines (97 loc) · 4.15 KB
/
additional_practice_20210819.R
File metadata and controls
134 lines (97 loc) · 4.15 KB
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
#tidying data
library(tidyverse)
library(lubridate)
#Data Wrangling--------------------------------------------
secchi_data <- read.csv('Secchi data 20210317.csv')
glimpse(secchi_data)
unique(secchi_data$Located.on.Feature.Name)
#make a dataframe of annual mean secchi depth values
secchi_clean <- secchi_data %>%
mutate(Date = ymd(Sample.Start.Date),
Year = year(Date)) %>%
filter(Located.on.Feature.Name == "A2R009 ROODEPLAAT DAM (PIENAARS RIVER) AT ROODEPLAAT") %>%
group_by(Year) %>%
summarise(Secchi = mean(SECCHI.Phys.Water..SECCHI...m..Result,na.rm=TRUE))
#using summarise_all()
water <- read.csv('water_quality.csv')
glimpse(water)
water_clean <- water %>%
mutate(Date = ymd(Sample.Start.Date),
Year = year(Date)) %>%
filter(Located.on.Feature.Name == "A2R009 ROODEPLAAT DAM (PIENAARS RIVER) AT ROODEPLAAT") %>%
select(Year,contains('Result')) %>%
group_by(Year) %>%
summarise_all(.funs = mean,na.rm=TRUE) %>%
rename(Chlorophyll = CHL.A.Susp.Water..CHLOROPHYLL.A...ug.L..Result,
Turbidity = TURB.Phys.Water..TURBIDITY...NTU..Result,
TOC = OC.Total.Water..ORGANIC.CARBON.TOTAL...mg.L..Result,
DOC = OC.Diss.Water..ORGANIC.CARBON...mg.L..Result,
TSS = SOLIDS.Susp.Water..TOTAL.SUSPENDED.SOLIDS...mg.L..Result)
#using merge()
water_all <- merge(x = secchi_clean, y = water_clean,
by.x = 'Year', by.y = 'Year',
all = TRUE)
#Plotting---------------------------------------------------------------------
#plot all variables
water_plot <- water_all %>%
pivot_longer(cols = 2:7,
names_to = "Variable",
values_to = "Value") %>%
filter(!is.nan(Value))
ggplot(water_plot,aes(Year,Value))+
geom_point()+
geom_line()+
facet_wrap(~Variable,scales='free')
secchi_data <- read.csv('Secchi data 20210317.csv')
glimpse(secchi_data)
unique(water$Located.on.Feature.Name)
#make a dataframe of annual mean secchi depth values
secchi_clean <- secchi_data %>%
mutate(Date = ymd(Sample.Start.Date),
Year = year(Date)) %>%
filter(Located.on.Feature.Name %in% unique(water$Located.on.Feature.Name)[1:5]) %>%
group_by(Year,Located.on.Feature.Name) %>%
summarise(Secchi = mean(SECCHI.Phys.Water..SECCHI...m..Result,na.rm=TRUE))
#using summarise_all()
water <- read.csv('water_quality.csv')
glimpse(water)
water_clean <- water %>%
mutate(Date = ymd(Sample.Start.Date),
Year = year(Date)) %>%
filter(Located.on.Feature.Name %in% unique(water$Located.on.Feature.Name)[1:5]) %>%
select(Year,Located.on.Feature.Name,contains('Result')) %>%
group_by(Year,Located.on.Feature.Name) %>%
summarise_all(.funs = mean,na.rm=TRUE) %>%
rename(Chlorophyll = CHL.A.Susp.Water..CHLOROPHYLL.A...ug.L..Result,
Turbidity = TURB.Phys.Water..TURBIDITY...NTU..Result,
TOC = OC.Total.Water..ORGANIC.CARBON.TOTAL...mg.L..Result,
DOC = OC.Diss.Water..ORGANIC.CARBON...mg.L..Result,
TSS = SOLIDS.Susp.Water..TOTAL.SUSPENDED.SOLIDS...mg.L..Result)
water_all <- merge(x = secchi_clean, y = water_clean,
by.x = c('Year','Located.on.Feature.Name'), by.y = c('Year','Located.on.Feature.Name'),
all = TRUE)
water_plot <- water_all %>%
pivot_longer(cols = 3:8,
names_to = "Variable",
values_to = "Value") %>%
filter(!is.nan(Value))
ggplot(water_plot,aes(Year,Value,color=Located.on.Feature.Name))+
geom_point()+
geom_line()+
facet_wrap(~Variable,scales='free')+
theme_bw()+
theme(legend.position = 'bottom')
water_cor <- water_all %>%
select(-DOC,-TOC,-Turbidity) %>%
filter(!is.na(Secchi),!is.nan(Chlorophyll),!is.nan(TSS))
install.packages('GGally')
library(GGally)
ggpairs(water_cor %>% select(-Year))
library(adklakedata)
library(corrplot)
lakes <- adk_data('chem')
lakes_cor <- lakes %>%
select(-PERMANENT_ID,-lake.name,-date,-year,-month)
cor_matrix <- cor(lakes_cor,use='pairwise.complete.obs')
corrplot(cor_matrix,type='lower')
ggpairs(lakes_cor[complete.cases(lakes_cor),1:10])