-
Notifications
You must be signed in to change notification settings - Fork 1
/
rmarkdown_bt.Rmd
172 lines (130 loc) · 4.7 KB
/
rmarkdown_bt.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
---
title: "markdown_bt"
author: "Benson Truong"
date: "2/22/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
# Attach Packages
library(tidyverse)
library(here)
library(janitor)
library(sf)
library(tmap)
library(mapview)
```
### Yosemite
```{r}
# Read in data
yosemite <- read.csv(here("data", "Animals", "yosemite.csv")) %>%
clean_names()
# Select Columns
yosemite_clean <- yosemite %>%
select(longitude, latitude, common_name, iconic_taxon_name) %>%
mutate(iconic_taxon_name = as.character(iconic_taxon_name)) %>%
filter(iconic_taxon_name != "Animalia")
# Convert into spatial data
yosemite_sf <- st_as_sf(yosemite_clean, coords = c("longitude", "latitude"),
crs = 4326)
# plot(yosemite_sf)
```
### Sequoia
```{r}
# Read in data
sequoia <- read.csv(here("data", "Animals", "sequoia.csv")) %>%
clean_names()
# Select Columns
sequoia_clean <- sequoia %>%
select(longitude, latitude, common_name, iconic_taxon_name) %>%
mutate(iconic_taxon_name = as.character(iconic_taxon_name))
# Convert into spatial data
sequoia_sf <- st_as_sf(sequoia_clean, coords = c("longitude", "latitude"),
crs = 4326)
plot(sequoia_sf)
```
## Tab 2
```{r}
# 1.) Read in NPS 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)
```
```{r}
# 2.) Animal observations
# 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)
```
```{r}
# 3.) 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)
#plot(park_animals)
```
```{r}
# 4.) Data and plots based on Natural Park
ci_nps <- nps_ca %>%
filter(unit_name %in% c("Channel Islands National Park")) %>%
dplyr::select(unit_name)
ci_animals <- park_animals %>%
filter(park == "Channel Islands National Park")
ci_plot <- ggplot()+
geom_sf(data = ci_nps,
fill = "grey") +
geom_sf(data = ci_animals,
aes(fill = iconic_taxon_name,
color = iconic_taxon_name),
alpha = .2)
ci_plot
```