This document is a work in progress, please give us feedback
In this tutorial we are going to work with the order of mammals Hyracoidea
commonly known as Hyraxes
The R package taxize
allows us to extract the IUCN status automatically. However, the functions of this package require an API key. Get the key at http://apiv3.iucnredlist.org/api/v3/token, and pass it to the key parameter, or store in your .Renviron file like IUCN_REDLIST_KEY=yourkey
The function iucn_summary
in the taxize package requires as an input the binomial name of the species
Hyracoidea$Binomial<-paste(Hyracoidea$genus,Hyracoidea$species)
ia <- iucn_summary(Hyracoidea$Binomial)
species_iucn<-iucn_status(ia)
## Include the info into the data frame
Hyracoidea$iucn<-species_iucn
## Binomial iucn
## 1 Dendrohyrax arboreus LC
## 2 Dendrohyrax dorsalis LC
## 3 Heterohyrax brucei LC
## 4 Procavia capensis LC
We need to define both column genus
and species
as characters before we use them on the gbif
function. They were pre-defined as factors.
Since we don’t need all the information extracted from gbif, here we will select only the species
,lat
,lon
,fullCountry
variables
foreach
gbif_records <-
foreach(i=1:length(Hyracoidea$Binomial),.combine = rbind)%do%{
gbif(Hyracoidea$genus[i],Hyracoidea$species[i])[c("species","lat","lon","fullCountry")]
}
Before merging our GBIF record into the life-history trait data frame, remember to clean your geographic data
## Cleaning records
gbif_records<-
gbif_records %>%
dplyr::filter(!is.na(lon)&!is.na(lat))
## Get rid of duplicate occurrences
dups=duplicated(gbif_records[, c("lon", "lat")])
gbif_records <-gbif_records[!dups, ]
## Merging data frames
Hyracoidea_df<-merge(Hyracoidea,gbif_records, by.x="Binomial", by.y="species")
The terrestrial ecoregions of the world (TEOW) from the World Wild Fund (WWF) represent a biogeographic framework to map earth’s biodiversity. This framework is mainly based on the publication by Olson et al., 2001.
Olson, D. M., Dinerstein, E., Wikramanayake, E. D., Burgess, N. D., Powell, G. V. N., Underwood, E. C., D’Amico, J. A., Itoua, I., Strand, H. E., Morrison, J. C., Loucks, C. J., Allnutt, T. F., Ricketts, T. H., Kura, Y., Lamoreux, J. F., Wettengel, W. W., Hedao, P., Kassem, K. R. 2001. Terrestrial ecoregions of the world: a new map of life on Earth. Bioscience 51(11):933-938
This biogeographic regionalisation consists of 867 terrestrial ecoregions, classified into 14 biomes and eight realms.
To access these maps, you can either download the data from the WWF website or through the function WwfLoad()
from the R package speciesgeocodeR
To use the WwfLoad()
function, you only need to specify the directory path where you want the data to be store.
The WWF ecoregions are stored in a vector format, which represent discrete geometric locations (x,y values) known as vertices that define the shape of the spatial objects (e.g., points, lines and polygons). Here, the ecoregions and biomes are represented by spatial polygons which are usually stored in shapefiles
. There are several functions in R that allows you to read shapefiles. One is using the function shapefile
from the raster
package or the readOGR
function from the rgdal
package
require(raster)
wwf_eco<-shapefile("./data/spatial/WWF_ecoregions/official/wwf_terr_ecos.shp")
require(rgdal)
## readOGR("path","layerName")
wwf_eco <- readOGR("./data/spatial/WWF_ecoregions/official/",
"wwf_terr_ecos")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/echeverrialondono1/Desktop/Loops_shapefile/data/spatial/WWF_ecoregions/official", layer: "wwf_terr_ecos"
## with 14458 features
## It has 21 fields
ATTENTION: Please include the path of the directory where you store your spatial data into the .gitignore file to avoid problems with Github when you push your commits!
Like rasters, shapefiles are geospatial objects, and therefore they also include spatial data attributes such as Coordinate Reference System (CRS) and extent
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
## CRS arguments:
## +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
## class : Extent
## xmin : -180
## xmax : 180
## ymin : -89.89197
## ymax : 83.62313
In this exercise, we want to extract the information about the realms and biomes that fall on each of our species occurrences. To do that, we first need to convert our occurrence data into a spatial data frame, and second, we need to make sure our spatial data frame has the same projection and coordinate system as the spatial polygons.
# 1. Convert to spatial data frame
Hyracoidea_geo<-Hyracoidea_df
coordinates(Hyracoidea_geo)<-~lon + lat
# 2. Make sure both files have the same projection
proj4string(Hyracoidea_geo)<-proj4string(wwf_eco)
Now we can extract the information using the function over
from the sp
r package. This function overlay the ecoregions and biomes polygons on our spatial data frame and then retrieves the attributes for each occurrence.
biome_data<-over(Hyracoidea_geo,wwf_eco)[c("REALM","BIOME","G200_REGIO")]
# Include these three columns into our original data frame
Hyracoidea_df<-cbind(Hyracoidea_df,biome_data)
Hyracoidea_df<-droplevels(Hyracoidea_df)
kable(head(Hyracoidea_df[,c("lat","lon","fullCountry","REALM","BIOME","G200_REGIO")]))
lat | lon | fullCountry | REALM | BIOME | G200_REGIO |
---|---|---|---|---|---|
-1.357095 | 36.71865 | Kenya | AT | 7 | East African Acacia Savannas |
-1.356291 | 36.71974 | Kenya | AT | 7 | East African Acacia Savannas |
0.003221 | 36.94571 | Kenya | AT | 7 | East African Acacia Savannas |
-1.426575 | 35.07104 | Kenya | AT | 7 | East African Acacia Savannas |
-5.074732 | 38.70292 | Tanzania, United Republic of | AT | 1 | Eastern Arc Montane Forests |
-1.336434 | 36.77759 | Kenya | AT | 7 | East African Acacia Savannas |
As you can see, the BIOMES levels are represented by numbers. To look at the numbers equivalence, we need to check the metadata of the WWF biomes. In our example, 7 represents Tropical & Subtropical Grasslands, Savannas & Shrublands. and 1 Tropical & Subtropical Moist Broadleaf Forests. In the metadata, you can also check the meaning of each REALM abbreviation (e.g., AT is equivalent to Afrotropics).