-
Notifications
You must be signed in to change notification settings - Fork 15
/
2021_Presentation.Rmd
149 lines (121 loc) · 6.3 KB
/
2021_Presentation.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
---
title: "2021_Presentation"
output: html_document
---
# Visualizing Marine Protected Areas and Biodiversity
2021 team: Lei Ma, Enrique Montes, Liz Sutter, Caroline Cappello, Tasha Gownaris, Ben Tupper, Nick Record
2020 team: Abby Benson, Rene Francolini, Natalie Posdaljian, Natalie Low, Kyle Oliveira, Camille Ross, Sam McNeely, Nick Record, Camille Ross, Angel Segura, Ben Tupper
## Purpose
![MPA](MPA.png)
**OBIS**
OBIS is a global open-access data and information clearing-house on marine biodiversity for science, conservation and sustainable development
**MPAS**
Conserved waters for a number of reasons including economic resources, biodiversity conservation, and species protection
**IUCN Category**
The International Union for Conservation of Nature has 7 categoies for classifying protected areas, ranging from "Ia Strict Nature Reserve" to "VI Protected area with sustainable use of natural resources"
## Previous year's accomplishments
## Goals for this year
1. Create an RShiny interface to implement user input for
* selection and filtering of MPAs
* query of OBIS records based on selected MPAs
* display of biodiversity statistics correlating OBIS data with MPAs
2. Improve the backend functioning
## Demo of Shiny interface
<br>
<br>
<br>
<br>
## Preview of future features: Querying OBIS based on MPA polygons
```{r setup}
knitr::opts_chunk$set(echo = TRUE)
library(sf)
library(tidyverse)
library(reshape2)
library(robis)
library(leaflet)
library(ggplot2)
library(vegan)
source("R-code/robis-package.R")
# robis::occurrence() expect filtering polygons in a well-known-text represerntation (aka WKT)
extract_polygon_geometry <- function(polygon) {
polygon %>%
sf::st_geometry() %>%
sf::st_as_text()
}
get_one_mpa <- function(x, key){
robis::occurrence(geometry = sf::st_as_text(sf::st_convex_hull(sf::st_geometry(x))))
}
convert_mpa_to_WKT <- function(x){
st_as_text(st_convex_hull(st_geometry(x)))
}
get_datasets <- function(x){
get_one_dataset <- function(x, key){
robis::dataset(geometry=convert_mpa_to_WKT(x))
}
x %>%
dplyr::rowwise() %>%
dplyr::group_map(get_one_dataset, .keep=TRUE) %>%
dplyr::bind_rows()
}
```
```{r, cache=TRUE}
# reading in the global MDPA file
# global <- wdpa_read_global(filestream=TRUE)
# saveRDS(global, file="delete_after_ohw21_2.rds")
global <- readRDS("delete_after_ohw21_2.rds")
# subsetting for Belgium
belgium <- global %>% filter(ISO3 %in% "BEL")
# Retrieving all OBIS records for Belgium
# bel_spoc <- read_obis_country("Belgium")
# Getting a subregion's OBIS records
#belgium_sub_obis <- filter(belgium, WDPAID==555536868) %>% get_one_mpa()
#saveRDS(belgium_sub_obis, "delete_after_ohw21.rds")
belgium_sub_obis <- readRDS("delete_after_ohw21.rds")
```
## Belgium's OBIS data
We chose to use Belgium as an example for this section because it's very data rich for OBIS. The main OBIS office is in Belgium! In this small area there are over half and million observations. Here's an example of what the OBIS tables look like:
```{r display OBIS table}
head(belgium_sub_obis %>% select(scientificName, class, infraclass, genus, eventDate))
```
So, even though Belgium's MPAs are a small area, for the purposes of this demo, we're going to only pull OBIS records for the tiny region in the northeast. In the Shiny App, we plan on having the user select MPAs by clicking or filtering by certain parameters such as IUCN category or year established and only pulling OBIS records from those regions.
```{r plotting belgium}
# plot an example map of Belgium
leafletplot <- leaflet(data=belgium) %>% addProviderTiles(providers$Stamen.Watercolor, options = providerTileOptions(noWrap = TRUE)) %>% addPolygons(popup = ~sprintf("%s", WDPAID))
leafletplot
```
Here are all the observations from that region
```{r visualize OBIS record locations}
# Visualize OBIS records for this
belgium_sub <- filter(belgium, WDPAID==555536868)
leaflet() %>%
addProviderTiles(provider = providers$Stamen.Watercolor) %>%
addPolygons(data=belgium_sub) %>%
addCircleMarkers(lat = belgium_sub_obis$decimalLatitude, lng = belgium_sub_obis$decimalLongitude, radius = 3, weight = 0, fillOpacity = .7, fillColor = "#CC3300")
```
## Biodiversity measurements for this region
**Explanation of ES50 measurement***
```{r}
# remove terrestrial species
species_occurence <- belgium_sub_obis %>% filter(terrestrial==FALSE)
# make species abundance table by year
species_occurence <- species_occurence %>% group_by(date_year, scientificName) %>% summarise(occurences = n())
```
```{r}
species_occurence %>% group_by(date_year) %>% summarise(total_occ = sum(occurences)) %>% ggplot(aes(x=date_year, y=total_occ))+geom_line()+labs(x="Year", y="Total occurences (all species", title="Uneven sampling effort through the years")
```
ES50 is also sensitive to the total number of species. It's generally best when there are >50 species
```{r}
# unique species by year
belgium_sub_obis %>% filter(date_year>1975 & date_year<2018) %>% group_by(date_year) %>% summarise(unqs=length(unique(scientificName))) %>% ggplot(aes(x=date_year, y=unqs))+geom_line()+labs(x="Year", y="Unique species")+geom_hline(yintercept=50)
```
So, let's look at ES50 before and after 2010, which is when this region was established as an MPA
```{r}
year <- belgium_sub$STATUS_YR
species_occurence <- mutate(species_occurence, before=date_year<year)
occurence_matrix_before <- species_occurence %>% filter(before) %>% select(-before) %>% pivot_wider(names_from = date_year, values_from=occurences, names_sort=TRUE, values_fill=0)
occurence_matrix_after <- species_occurence %>% filter(!before) %>% select(-before) %>% pivot_wider(names_from = date_year, values_from=occurences, names_sort=TRUE, values_fill=0)
occurence_matrix <- species_occurence %>% select(-before) %>% pivot_wider(names_from = scientificName, values_from=occurences, names_sort=TRUE, values_fill=0) %>% filter(!is.na(date_year)) %>% column_to_rownames(var="date_year")
es50<-rarefy(occurence_matrix, 50) %>% as_tibble(rownames="date_year")
ggplot(es50 %>% filter(date_year>1975 & date_year<2018), aes(x=as.numeric(date_year), y=value)) + geom_line() + geom_vline(xintercept = year, color="green") + labs(x="Year", y="ES50")
```
This graph illustrates why the choice of MPA is very important. The MPA needs to be in a data rich region for OBIS records, and needs to have been established long enough ago to see effects.