-
Notifications
You must be signed in to change notification settings - Fork 1
/
shuhan_scratch.Rmd
168 lines (124 loc) · 4.47 KB
/
shuhan_scratch.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
---
title: "shuhan scratch"
author: "Designed and made by Shuhan Song"
date: "2/29/2020"
output: html_document
---
```{r}
library(shiny)
library(tidyverse)
library(kableExtra)
library(shinythemes)
library(here)
library(janitor)
library(paletteer)
library(raster)
library(sf)
library(tmap)
library(leaflet)
library(ggplot2)
# Read in data
## read in national parks boundaries
nps <- read_sf(dsn = here("data", "National_Park_Service__Park_Unit_Boundaries"),
layer = "National_Park_Service__Park_Unit_Boundaries", crs = 4326) %>%
clean_names()
nps_ca <- nps %>%
filter(state == "CA")
nps_ca_five <- nps_ca %>%
filter(unit_name %in% c("Death Valley National Park", "Joshua Tree National Park", "Yosemite National Park", "Channel Islands National Park", "Sequoia National Park")) %>%
dplyr::select(unit_name)
#plot(nps_ca_five)
# Read in park data
# Channel islands
channel_islands <- read_csv(here::here("data", "Animals", "channel_islands.csv")) %>%
dplyr::select(latitude, longitude, common_name, iconic_taxon_name) %>%
mutate(iconic_taxon_name = as.character(iconic_taxon_name)) %>%
filter(!iconic_taxon_name %in% c("Actinopterygii", "Animalia")) %>%
mutate(park = "Channel Islands National Park")
channel_islands_sf <- st_as_sf(channel_islands,
coords = c("longitude", "latitude"),
crs = 4326)
# Death Valley
death_valley <- read_csv(here::here("data", "Animals", "death_valley.csv")) %>%
dplyr::select(latitude, longitude, common_name, iconic_taxon_name) %>%
filter(!iconic_taxon_name == "Animalia") %>%
mutate(park = "Death Valley National Park")
death_valley_sf <- st_as_sf(death_valley,
coords = c("longitude", "latitude"),
crs = 4326)
# Joshua Tree
joshua_tree <- read_csv(here::here("data", "Animals", "joshua_tree.csv")) %>%
dplyr::select(latitude, longitude, common_name, iconic_taxon_name) %>%
filter(!iconic_taxon_name %in% c("Animalia", "Plantae")) %>%
mutate(park = "Joshua Tree National Park")
joshua_tree_sf <- st_as_sf(joshua_tree,
coords = c("longitude", "latitude"),
crs = 4326)
# Yosemite
yosemite <- read.csv(here("data", "Animals", "yosemite.csv")) %>%
clean_names()
yosemite_clean <- yosemite %>%
dplyr::select(longitude, latitude, common_name, iconic_taxon_name) %>%
mutate(iconic_taxon_name = as.character(iconic_taxon_name)) %>%
filter(iconic_taxon_name != "Animalia") %>%
mutate(park = "Yosemite National Park")
yosemite_sf <- st_as_sf(yosemite_clean, coords = c("longitude", "latitude"),
crs = 4326)
# Sequoia
sequoia <- read.csv(here("data", "Animals", "sequoia.csv")) %>%
clean_names()
sequoia_clean <- sequoia %>%
dplyr::select(longitude, latitude, common_name, iconic_taxon_name) %>%
mutate(iconic_taxon_name = as.character(iconic_taxon_name)) %>%
mutate(park = "Sequoia National Park")
sequoia_sf <- st_as_sf(sequoia_clean, coords = c("longitude", "latitude"),
crs = 4326)
# join species observations data
animal <- rbind(channel_islands_sf, death_valley_sf, yosemite_sf, sequoia_sf, joshua_tree_sf)
# ONLY keep *animal points* inside the polygons
park_animals <- st_join(animal, nps_ca_five, left = FALSE) %>%
filter(!common_name %in% c("Birds", "Mammals", "Reptiles", "Snakes", "Amphibians", "NA"))
# Also get the lat & long for the animal observations, lon - X, lat - Y
park_animals_coords <- data.frame(park_animals[1:3],
sf::st_coordinates(park_animals))
```
```{r}
ggplot(data = nps_ca_five) +
geom_sf()+
coord_sf(xlim = c(-120.6, -119),
ylim = c(33.3, 34.5))
```
```{r}
ggplot(data = nps_ca_five) +
geom_sf() +
coord_sf(xlim = c(-119, -118.2),
ylim = c(36.2, 36.8))
```
```{r}
ggplot(data = nps_ca_five) +
geom_sf() +
coord_sf(xlim = c(-120, -119.1),
ylim = c(37.5, 38.2))
```
```{r}
ggplot(data = nps_ca_five) +
geom_sf() +
coord_sf(xlim = c(-116.7, -115),
ylim = c(33.5, 34.3))
```
```{r}
ggplot(data = nps_ca_five) +
geom_sf() +
coord_sf(xlim = c(-118.1, -116.2),
ylim = c(35.6, 37.4))
```
```{r}
animal_park <- park_animals %>%
dplyr::select(common_taxon)
count(common_taxon)
park_hist <- ggplot(data = animal_park(),
aes(x = common_taxon, y = n)) +
geom_col(aes(color = common_taxon),
show.legend = FALSE) +
theme_minimal()
```