-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.rmd
183 lines (124 loc) · 3.59 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
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
---
title: "Data Vizualization"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
I used the following Libraries for this page
```{r warning=FALSE, message=FALSE}
library(dplyr)
library(tidyr)
library(ggplot2)
library(scales)
library(leaflet)
library(DT)
# these libraries have their own filter,lag functions. to call stats file, use stats::filter()
```
#Reformat Data for Plotting
data from : https://knb.ecoinformatics.org/view/doi:10.5063/F1S46Q6M
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, echo=F}
esc <- read.csv(url("https://knb.ecoinformatics.org/knb/d1/mn/v2/object/urn%3Auuid%3Af119a05b-bbe7-4aea-93c6-85434dcb1c5e", method="libcurl"), stringsAsFactors = FALSE)
```
* calculate annual escapement by species and region
* filter for just pacific salmon (Sockeye, Chinook, coho, pink, chum)
```{r}
annual_esc <- esc %>%
separate(sampleDate, into = c("year", "month", "day"), sep = "-") %>%
mutate(year = as.numeric(year)) %>% #make numeric
group_by(year, Species, SASAP.Region) %>%
summarise(count=sum(DailyCount)) %>%
filter(Species %in% c("Chinook","Sockeye","Chum","Coho","Pink"))
#head(annual_esc)
```
```{r}
```
```{r}
```
#Generate some static plots
```{r }
ggplot(annual_esc, aes(x = Species, y = count)) +
geom_col( fill="lavender")
```
```{r}
ggplot(annual_esc) +
geom_col(aes(x = Species, y = count), fill="purple")
```
```{r}
ggplot(annual_esc, aes(x = Species, y = count, fill = SASAP.Region)) +
geom_col()
```
## just plot Kodiak
```{r}
ggplot(filter(annual_esc, SASAP.Region == "Kodiak"), aes(x = year, y = count, color = Species)) +
geom_line() +
geom_point() +
ylab("Escapement (num of fish)") +
xlab("year") +
ggtitle("Kodiak Salmon Escapement") +
theme_test() +
theme(legend.position="bottom")
```
```{r}
my_theme <- theme_test() +
theme(legend.position="bottom",
legend.title=element_blank())
```
```{r}
ggplot(filter(annual_esc, SASAP.Region == "Kodiak"), aes(x = year, y = count, color = Species)) +
geom_line() +
geom_point() +
ylab("Escapement (num of fish)") +
xlab("year") +
ggtitle("Kodiak Salmon Escapement") +
my_theme
```
##Mulitple plts
```{r fig.width = 7, fig.height=8}
p <- ggplot(annual_esc, aes(x = year, y = count, color = Species)) +
geom_line() +
geom_point() +
scale_y_continuous(label=comma) +
facet_wrap(~SASAP.Region, scales = "free_y", ncol=2) +
ylab("Escapement") +
my_theme
p
ggsave("figures/regional_escapement.png",
plot=p,
width=7,
height=8,
units = "in")
```
# Create Interactive Map
* map the sampling locations for escapement
* find distinct lat/lon combinations
```{r}
locations <- esc %>%
distinct(Location, Latitude, Longitude) %>%
drop_na()
```
```{r, echo=F}
datatable(locations)
```
### now make the map
<br/>
<br/>
<br/>
<br/>
<br/>
```{r}
leaflet(locations) %>%
addTiles()
```
```{r}
leaflet(locations) %>%
addTiles() %>%
addMarkers(lng = ~Longitude, lat= ~ Latitude, popup = ~ Location)
```
```{r}
leaflet(locations) %>%
addTiles(urlTemplate="http://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga") %>%
addMarkers(lng = ~Longitude, lat= ~ Latitude, popup = ~ Location)
```
leaflet() %>% addTiles(urlTemplate = "https://mts1.google.com/vt/lyrs=s&hl=en&src=app&x={x}&y={y}&z={z}&s=G", attribution = 'Google')