-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
110 lines (84 loc) · 2.62 KB
/
index.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
---
title: "Index"
author: "Patricia DeRepentigny"
date: "1/17/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{r, echo=F}
library(dplyr)
library(tidyr)
library(ggplot2)
library(DT)
library(leaflet)
```
# Data Tidying
Read in escapement data sourced from: Alaska Department of Fish and Game, Division of Commercial Fisheries. 2017. Daily salmon escapement counts from the OceanAK database, Alaska, 1921-2017. Knowledge Network for Biocomplexity. doi:10.5063/F1S46Q6M.
```{r, results=F}
esc <- read.csv("https://knb.ecoinformatics.org/knb/d1/mn/v2/object/urn%3Auuid%3Af119a05b-bbe7-4aea-93c6-85434dcb1c5e",
stringsAsFactors = FALSE)
head(esc)
```
Calculate annual, regional total escapement by species:
* `separate` the date into year - month - day
* `group_by` and `summarize` to calculate the sum over unique region-year-species combinations
* `filter` for salmon species
```{r}
annual_esc <- esc %>%
separate(sampleDate, into = c("year", "month", "day"), sep = "-") %>%
mutate(year = as.numeric(year)) %>%
group_by(SASAP.Region, Species, year) %>%
summarise(escapement = sum(DailyCount)) %>%
filter(Species %in% c("Chinook", "Sockeye", "Pink", "Chum", "Coho"))
```
```{r}
datatable(annual_esc)
```
# Static Plots
```{r}
ggplot(data = annual_esc, mapping = aes(x = Species, y = escapement, fill = SASAP.Region)) +
geom_col()
```
Timeseries of Kodiak escapement by species.
```{r}
my_theme <- theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
ggplot(data = filter(annual_esc, SASAP.Region == "Kodiak"),
aes(x = year, y = escapement, color = Species)) +
geom_line() +
geom_point() +
ylab("Escapement (number of fish)") +
ggtitle("Kodiak Salmon Escapement") +
my_theme
```
Plot timeseries of escapement by species for all regions
```{r, fig.height = 10, fig.width = 8}
p <- ggplot(annual_esc, aes(x = year, y = escapement, color = Species)) +
geom_line() +
geom_point() +
facet_wrap(~SASAP.Region, scales = "free", ncol = 2) +
my_theme
p
ggsave("Figures/region_escapement.eps", plot = p, height = 10, width = 8, units = "in")
```
Write derived data to a csv file
```{r}
write.csv(annual_esc, "Derived_data/annual_escapement.csv", row.names = F)
```
# Interactive Map
Make a map using leaflet:
* Find unique location with lat/lon values
```{r}
locations <- esc %>%
distinct(Location, Latitude, Longitude) %>%
drop_na()
datatable(locations)
```
Create our interactive map
```{r}
leaflet(locations) %>%
addTiles() %>%
addMarkers(~Longitude, ~Latitude, popup = ~Location)
```