-
Notifications
You must be signed in to change notification settings - Fork 2
/
Readme.Rmd
264 lines (209 loc) · 9.16 KB
/
Readme.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
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
---
title: "KEEN Raw Data and code to Clean and Merge"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message=FALSE, warning=FALSE)
```
### Cleaning and Merging the KEEN Data
This repo contains the raw data from KEEN member nodes, the scripts used to clean and merge them, and the ultimate clean data to be depositived in Temperate ReefBase.
To clean and merge data, run the numbered scripts in the R folder in order. Note, the first script will use the species lists provided by regional coordinators to generate a master list for each region by querying WoRMS for current taxonomy.
The data QC script will also generate output error logs to diagnose any problems with the data at hand, beyond things that cause scripts to fail.
## Adding your site's data
To contribute data, contact [email protected]. You will need to use the data entry templates at https://github.com/kelpecosystems/materials/tree/master/Data%20Entry/Observational%20Sampling and make sure your region has a species list. You should have already contacted Jarrett and your [regional coordinator](http://www.kelpecosystems.org/members/regional-coordinators/) for sampling (or it should be on https://github.com/kelpecosystems/materials/ in the species list section). If you are using your own, make sure it is formatted properly.
## I want to contribute my program's data, but our protocol is different
We'd love to make this work! Again, contact [email protected]. You'll need to synch up a KEEN survey with your own survey for one site so that we can figure out how to cross-compare the datasets and build a pipeline to convert your data into KEEN data. If you're already done this, mazel tov! Let's get to work!
## Using the Cleaned Data
The `cleaned_data` folder contains the end-products of the data merging pipeline split into serveral files. Currently we have
keen_sites.csv - The spatial information for all transects sampled
keen_cover.csv - Results from Uniform Point Counts standardized to % cover
keen_fish.csv - Fish abundances in different size classes
keen_quads.csv - Counts of individual algae, inverts, and small fish in 1x1m quadrats
keen_swath.csv - Counts of more rare algae, inverts, and small fish in 20x1m areas.
The data all have common keys of `SITE`, `TRANSECT`, and `YEAR` to be easily merged. Let's see this in action.
## Making a Map of KEEN ONE sites.
To examine KEEN ONE sites, let's use `ggmap` to plot them.
First we'll load a few needed libraries
```{r libraries, message=FALSE, warning=FALSE}
library(tidyverse) #for dplyr and tidyr
library(forcats) #for factor manipulation
library(ggmap) #loads ggplot2 as well
```
Then load the data
```{r}
sites <- read.csv("./cleaned_data/keen_sites.csv",
stringsAsFactors=FALSE)
```
Next, we want to get a single lat/long value for each site, so let's use their means over time.
```{r}
sites_summary <- sites %>%
group_by(SITE) %>%
summarize(START_LATITUDE = mean(START_LATITUDE, na.rm=T),
START_LONGITUDE = mean(START_LONGITUDE, na.rm=T)) %>%
ungroup() %>%
arrange(START_LATITUDE)
```
I've arranged by start latitude for some purposes in future plots. Now, let's plot them!
```{r ggmap_plot}
keen_one_map <- get_map("Gulf of Maine",
zoom=7,
maptype="roadmap")
ggmap(keen_one_map) +
geom_point(data=sites_summary,
mapping=aes(x=START_LONGITUDE,
y = START_LATITUDE),
size=3) +
theme_nothing()
```
## Quadat counts of kelp
One of the first things you might want to do when plotting data is to join it with site information to, say, order things from south to north. Here, we'll do that with a `left_join` from `dplyr` and then use `fct_reorder` from `forcats` to arrange sites in the proper order
```{r}
quads <-read.csv("./cleaned_data/keen_quads.csv",
stringsAsFactors=FALSE) %>%
select(-DAY, -MONTH) %>%
left_join(sites_summary) %>%
mutate(SITE = factor(SITE)) %>%
mutate(SITE = fct_reorder(SITE, START_LATITUDE))
```
With the data prepped, we'll plot the trjectories both looking at trendlines, and the mean and SE for each site in each year.
```{r kelp_plot_quad, warning=FALSE}
kelp_summary_quad <- quads %>%
filter(SP_CODE == "SL") %>%
group_by(SITE, YEAR, PI) %>%
summarise(COUNT = mean(COUNT, na.rm=T))
ggplot(kelp_summary_quad,
aes(x=YEAR, y=COUNT, color=SITE, shape=PI)) +
geom_line() +
stat_summary(data=quads %>%
filter(SP_CODE == "SL")) +
theme_bw(base_size=18) +
scale_x_continuous(breaks=c(2014, 2015, 2016)) +
labs(title="Saccharina latissima") +
ylab("# Per Square Meter") + xlab("")
```
## Biplots of Different Species with Swaths
The data here is in a long format. Many species are missing from each sample, as they were not present. If we want to make biplots of one species against another, we will both have to reshape the data to a wide format as well as fill in all of those zeroes. Fortunately, this is straightforwad with tools like the `tidyr` library.
Let's load the swath data...
```{r load_swath}
swath <-read.csv("./cleaned_data/keen_swath.csv",
stringsAsFactors=FALSE)
```
and now we can reshape it
```{r reshape}
swath_wide <- swath %>%
select(-(GROUP:NOTES)) %>%
spread(SP_CODE, COUNT, fill=0)
```
and finally plot it, using a jitter plot to deal with overlapping values
```{r biplot}
ggplot(swath_wide,
aes(x=HOAM, y=CABO, color=SITE)) +
geom_jitter() +
xlab("Lobster per 20 sq m") +
ylab("Jonah Crab per 20 sq m")
```
## More?
If you have other types of analyses you'd like to see here, please, file an issue report and I'll add it!
```{r echo=FALSE, eval=FALSE}
ggplot(kelp_summary_quad %>%
filter(PI =="Byrnes") %>%
filter(SITE != "Cape Elizabeth")%>%
filter(SITE != "SW Appledore") ,
aes(x=YEAR, y=COUNT, color=SITE)) +
geom_line() +
stat_summary(data=quads %>%
filter(SP_CODE == "SL")%>%
filter(PI =="Byrnes")%>%
filter(SITE != "Cape Elizabeth")%>%
filter(SITE != "SW Appledore")) +
theme_bw(base_size=18) +
scale_x_continuous(breaks=c(2014, 2015, 2016)) +
labs(title="Saccharina latissima") +
ylab("# Per Square Meter") + xlab("")
## All Kelp Quad
akq <- quads %>%
filter(ORDER =="Laminariales") %>%
filter(SITE != "Cape Elizabeth")%>%
filter(SITE != "SW Appledore")%>%
filter(SITE != "Nubble") %>%
group_by(PI, SITE, START_LATITUDE, TRANSECT, YEAR) %>%
summarise(COUNT = sum(COUNT, na.rm=T)/6) %>%
ungroup()
ggplot(akq %>% group_by(START_LATITUDE) %>%
summarise(COUNT = mean(COUNT))) +
aes(x=START_LATITUDE, y=COUNT) +
geom_point()
ggplot(data=akq) +
aes(x=SITE, y=COUNT) +
geom_boxplot()
ggplot(data=akq) +
aes(x=YEAR, y=COUNT) +
stat_summary() +
scale_x_continuous(breaks=c(2014:2016)) +
geom_line(data=akq %>% group_by(YEAR) %>% summarise(COUNT=mean(COUNT)) %>% ungroup()) +
theme_bw(base_size=17) +
ylab("# Kelps per sq m") +
xlab("") +
annotate(geom="text",
x=2014:2016, y=17.5,
label=c("2.7ºC", "2.0ºC", "4.8ºC"),
size=4)
ggplot(data=akq %>% filter(PI=="Byrnes")) +
aes(x=YEAR, y=COUNT, color=SITE) +
stat_summary() +
scale_x_continuous(breaks=c(2014:2016)) +
geom_line(data=akq %>%
filter(PI=="Byrnes") %>%
group_by(YEAR, SITE) %>%
summarise(COUNT=mean(COUNT)) %>% ungroup()) +
theme_bw(base_size=17) +
ylab("# Kelps per sq m") +
xlab("") +
scale_color_manual(values=RColorBrewer::brewer.pal(6, "RdBu"))
## All Kelp Cover
cover <-read.csv("./cleaned_data/keen_cover.csv",
stringsAsFactors=FALSE) %>%
select(-DAY, -MONTH) %>%
left_join(sites_summary) %>%
mutate(SITE = factor(SITE)) %>%
mutate(SITE = fct_reorder(SITE, START_LATITUDE))
akc <- cover %>%
filter(ORDER =="Laminariales") %>%
filter(SITE != "Cape Elizabeth")%>%
filter(SITE != "SW Appledore")%>%
filter(SITE != "Nubble") %>%
group_by(PI, START_LATITUDE, SITE, TRANSECT, YEAR) %>%
summarise(PERCENT_COVER = sum(PERCENT_COVER, na.rm=T)) %>%
ungroup()
ggplot(data=akc) +
aes(x=SITE, y=PERCENT_COVER) +
geom_boxplot()
ggplot(data=akc) +
aes(x=YEAR, y=PERCENT_COVER) +
stat_summary() +
scale_x_continuous(breaks=c(2014:2016)) +
geom_line(data=akc %>% group_by(YEAR) %>% summarise(PERCENT_COVER=mean(PERCENT_COVER)) %>% ungroup()) +
theme_bw(base_size=17) +
ylab("Kelp % Cover") +
xlab("")
ggplot(data=akc %>% filter(PI=="Byrnes")) +
aes(x=YEAR, y=PERCENT_COVER, color=SITE) +
stat_summary() +
scale_x_continuous(breaks=c(2014:2016)) +
geom_line(data=akc %>%
filter(PI=="Byrnes") %>%
group_by(YEAR, SITE) %>%
summarise(PERCENT_COVER=mean(PERCENT_COVER)) %>% ungroup()) +
theme_bw(base_size=17) +
ylab("# Kelps per sq m") +
xlab("") +
scale_color_manual(values=RColorBrewer::brewer.pal(6, "RdBu"))
ggplot(akc) +
aes(x=START_LATITUDE, y=PERCENT_COVER) +
geom_point() +
facet_wrap(~YEAR) + stat_smooth(method="lm")
mod <- lm(PERCENT_COVER ~ START_LATITUDE*factor(YEAR), data=akc)
car::Anova(mod)
summary(mod)
coef(mod)[2] + coef(mod)[6]
```