1
install.packages("rgbif")
library("rgbif")
Species.Name <- "The name of the species"
#Search GBIF and download observations
Species.key <- name_backbone(name=Species.Name)$speciesKey
locations <- occ_search(taxonKey=Species.key,hasCoordinate = TRUE, return='data', limit=20000)

#Remove localities with uncertain coordinates - meaning the observer entered approximate latitude and longitude data. This is common with very old specimens/records that were collected prior to handheld GPS devices being invented
locations <- subset(locations, coordinateUncertaintyInMeters <= 5000)
head(locations)

### **Create a Map**

#### Install the maps package to download the political boundaries for the region of interest so we can map out the data.
```{r}
library(ggplot2)
#install.packages("maps")
# Download Country Boundaries
world <- map_data("world")

Not sure how to get the entire scope of Europe and Africa show these localities on the map.

1 Answer 1

1

At first you have to create spatial object from localities occurence data. These data is table with columns decimalLongitude and decimalLatitude. You can use sp or sf package for this.

# make spatial point object from lat,lon columns
library(sp)
sp_occs <- SpatialPoints(coords = locations[c("decimalLongitude","decimalLatitude")],
                         proj4string=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 "))

You can use base plot() which is handy for quick data inspection.

# download world polygon data
library(maptools)
data("wrld_simpl")

# plot both spatial objects
plot(wrld_simpl)
plot(sp_occs,add=T,col="red")

enter image description here

To crop polygons to desired extent you can use crop() function from raster package. This will crop your polygon object by other spatial object or defined boundaries (extent).

library(raster)
extent_eur <- extent(-30,50,-30,70)

eur <- crop(wrld_simpl,extent_eur)

# plot cropped polygons and species points
plot(eur)
plot(sp_occs,
    pch=20,
    col="red",
    add=T)

enter image description here

Note that we cropped only world polygons, not the occurence data. If you need subset of the occurence data in that region, just use crop() in the same way. Also if you need map of specific countries you can also subset the polygon data by attributes (i.e. name/code of country or region if it is available)

Code example for Mantis religiosa:

library(rgbif)
library(raster)#loads also "sp" package
library(maptools)

Species.Name <- "mantis religiosa"

Species.key <- name_backbone(name=Species.Name)$speciesKey
locations <- occ_search(taxonKey=Species.key,hasCoordinate = TRUE, return='data', limit=500)
locations <- subset(locations, coordinateUncertaintyInMeters <= 5000)

sp_occs <- SpatialPoints(coords = locations[c("decimalLongitude","decimalLatitude")],
                         proj4string=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 "))

data("wrld_simpl")
extent_eur <- extent(-30,50,-30,70)

eur <- crop(wrld_simpl,extent_eur)

plot(eur)
plot(sp_occs,
    pch=20,
    col="red",
    add=T)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.