Last updated: 2021-03-15
Checks: 6 1
Knit directory: mapme.protectedareas/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish
to commit the R Markdown file and build the HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20210305)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version c93be45. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Rproj.user/
Ignored: contributing.html
Ignored: mapme.protectedareas.Rproj
Ignored: renv/library/
Ignored: renv/local/
Ignored: renv/staging/
Unstaged changes:
Modified: .DS_Store
Modified: analysis/wwf_teow.rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/wwf_teow.rmd
) and HTML (docs/wwf_teow.html
) files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | c93be45 | Johannes Schielein | 2021-03-15 | update to teow routine |
Rmd | b548133 | Ohm-Np | 2021-03-15 | create wwf teow rmd |
html | b548133 | Ohm-Np | 2021-03-15 | create wwf teow rmd |
knitr::opts_knit$set(root.dir = '../')
# load required libraries
library("sf")
library("wdpar")
library("dplyr")
library("rmarkdown") # only used for rendering tables for this website
starttime<-Sys.time()
Description of the dataset from WWF:
Terrestrial Ecoregions of the World (TEOW) is a biogeographic regionalization of the Earth’s terrestrial biodiversity. Our biogeographic units are ecoregions, which are defined as relatively large units of land or inland water containing a distinct assemblage of natural communities sharing a large majority of species, dynamics, and environmental conditions. There are 867 terrestrial ecoregions, classified into 14 different biomes such as forests, grasslands, or deserts. Ecoregions represent the original distribution of distinct assemblages of species and communities.Visit Link for more information on TEOW from WWF.
Here we are going to carry out an analysis to see the level of intersection of different WDPA polygon layers with the Ecoregions; to answer how much area of wdpa polygon is within a particular type of ecoregion.
To carry out this analysis, we will follow this processing routine:
wdpar
wdpar
and clean the dataarea_proj
function & transform the projection system of polygonsFirst of all, we will try to get the country level polygon data from wdpar
package. wdpar
is a library to interface to the World Database on Protected Areas (WDPA). The library is used to monitor the performance of existing PAs and determine priority areas for the establishment of new PAs. We will use Brazil - for other countries of your choice, simply provide the country name or the ISO3 name e.g. Gy for Guyana, COL for Colombia
# fetch the raw data from wdpar of country
br_wdpa_raw <- wdpa_fetch("Brazil")
Since there are more than 3000 enlisted protected areas in Brazil, we are interested in only three wdpa polygons: - Reserva Biologica Do Rio Trombetas - wdpaid 43, - Reserva Extrativista Rio Cajari - wdpaid 31776, and - Estacao Ecologica Do Jari - wdpaid 4891
For this, we have to subset the country level polygon data to the PAs level.
# subset three wdpa polygons by their wdpa ids
br_wdpa_subset<-
br_wdpa_raw%>%
filter(WDPAID %in% c(43,4891,31776))
The next immediate step would be to clean the fetched raw data with the functionality provided with routines from the wdpar
package. Cleaning is done so as to:
For more information see the package documentation of wdpar
. In the end of this step we will project the data back to WGS84 for the intersection.
# clean the data
br_wdpa_subset <- wdpa_clean(
br_wdpa_subset,
erase_overlaps = F
)
# we can plot a feature of the data to see the three selected polygons
plot(br_wdpa_subset[1])
Since, we prepared WDPA polygon data for our analysis, we now load the TEOW global shapefile layer from archived file or if you want to download the teow global shapefile, you can download the file calling the function get_wwf_teow
.
# load TEOW global polygons
teow <-
read_sf(paste(getwd(),"/data/Terrestrial_Ecoregions_World.shp",sep=""))
# simplify geometry (this might be useful for other, very complex polygon layers)
# library("rmapshaper")
# teow_simp <-
# ms_simplify(teow)
To analyse how much of wdpa area is within which part of the ecoregion, intersection function is applied. st_intersection
allows us to see that result. To be able to apply st_intersection, the polygon layers should be saved as sf
object. To carry out intersection function, coordinate reference system of both the polygons should be same. For this, we use st_transform
to achieve this.
## reproject teow to match WDPA
teow <-
st_transform(teow,crs = st_crs(br_wdpa_subset))
# br_wdpa_subset<-st_transform(br_wdpa_subset,crs = st_crs(teow))
teow_wdpa_intersection <-
st_intersection(teow, br_wdpa_subset)
# plot intersection layer
plot(teow_wdpa_intersection[1])
Version | Author | Date |
---|---|---|
b548133 | Ohm-Np | 2021-03-15 |
We can see that there is one intersection for the polygon in the eastern part of the research area i.e that we now have for polygons whereas before the intersection we had only three.
Since, we already achieved the intersection, now we want to extract the actual area of interaction between wdpa polygons and teow polygons.
# ectract areas (Sqkm) and save it as new column
teow_wdpa_intersection$teow_intersect_sqkm <-
st_area(teow_wdpa_intersection)
# tibble - turns existing object to tibble dataframe from library `dplyr`
myData <- as_tibble(teow_wdpa_intersection)
# select only necessary columns from the intersected polygon
myData_f <- myData %>%
select(WDPAID, NAME, ECO_ID, ECO_NAME, BIOME, teow_intersect_sqkm)
With the results looking like this
In the end we are going to have a look how long the rendering of this file took so that people get an idea about the processing speed of this routine
stoptime<-Sys.time()
print(starttime-stoptime)
Time difference of -4.551091 secs
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_2.5 dplyr_1.0.5 wdpar_1.0.6 sf_0.9-7
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 pillar_1.4.7 compiler_4.0.3 later_1.1.0.1
[5] git2r_0.27.1 workflowr_1.6.2 class_7.3-17 tools_4.0.3
[9] digest_0.6.27 jsonlite_1.7.1 evaluate_0.14 lifecycle_1.0.0
[13] tibble_3.0.4 pkgconfig_2.0.3 rlang_0.4.10 DBI_1.1.0
[17] rstudioapi_0.13 curl_4.3 yaml_2.2.1 xfun_0.19
[21] e1071_1.7-4 httr_1.4.2 stringr_1.4.0 knitr_1.30
[25] rappdirs_0.3.3 generics_0.1.0 fs_1.5.0 vctrs_0.3.6
[29] tidyselect_1.1.0 classInt_0.4-3 rprojroot_2.0.2 grid_4.0.3
[33] glue_1.4.2 R6_2.5.0 purrr_0.3.4 magrittr_2.0.1
[37] whisker_0.4 promises_1.1.1 ellipsis_0.3.1 htmltools_0.5.0
[41] units_0.6-7 assertthat_0.2.1 countrycode_1.2.0 httpuv_1.5.4
[45] KernSmooth_2.23-17 stringi_1.5.3 lwgeom_0.2-5 crayon_1.3.4