NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true") knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE, purl = NOT_CRAN, eval = NOT_CRAN )
Seach and retrieve data from the Global Biodiverity Information Facilty (GBIF)
About the package
rgbif is an R package to search and retrieve data from the Global Biodiverity Information Facilty (GBIF).
rgbif wraps R code around the GBIF API to allow you to talk to GBIF from R.
Install from CRAN
Or install the development version from GitHub
Number of occurrences
Search by type of record, all observational in this case
Records for Puma concolor with lat/long data (georeferened) only. Note that
occ_search() is the same as
All georeferenced records in GBIF
Records from Denmark
denmark_code <- isocodes[grep("Denmark", isocodes$name), "code"] occ_count(country=denmark_code)
Number of records in a particular dataset
All records from 2012
Records for a particular dataset, and only for preserved specimens
Search for taxon names
Get possible values to be used in taxonomic rank arguments in functions
name_lookup() does full text search of name usages covering the scientific and vernacular name, the species description, distribution and the entire classification across all name usages of all or some checklists. Results are ordered by relevance as this search usually returns a lot of results.
name_lookup() returns five slots of information: meta, data, facets, hierarchies, and names. hierarchies and names elements are named by their matching GBIF key in the
data.frame in the data slot.
out <- name_lookup(query='mammalia')
Search for a genus
z <- name_lookup(query='Cnaemidophorus', rank="genus") z$data
Search for the class mammalia
w <- name_lookup(query='mammalia') w$data
Look up the species Helianthus annuus
m <- name_lookup(query = 'Helianthus annuus', rank="species") m$data
name_usage() works with lots of different name endpoints in GBIF, listed at https://www.gbif.org/developer/species#nameUsages
name_usage(key=3119195, language="FRENCH", data='vernacularNames')
name_backbone() is used to search against the GBIF backbone taxonomy
name_backbone(name='Helianthus', rank='genus', kingdom='plants')
name_suggest() is optimized for speed, and gives back suggested names based on query parameters.
head( name_suggest(q='Puma concolor') )
Single occurrence records
Get data for a single occurrence. Note that data is returned as a list, with slots for metadata and data.
Get many occurrences.
occ_get is vectorized
Search for occurrences
Note: The maximum number of records you can get with
occ_data() is 100,000. See https://www.gbif.org/developer/occurrence
occ_search() returns a
dplyr like output summary in which the data printed expands based on how much data is returned, and the size of your window. You can search by scientific name:
occ_search(scientificName = "Ursus americanus", limit = 20)
Or to be more precise, you can search for names first, make sure you have the right name, then pass the GBIF key to the
key <- name_suggest(q='Helianthus annuus', rank='species')$key occ_search(taxonKey=key, limit=20)
You can index to different parts of the oupu; here, the metadata:
You can choose what fields to return. This isn't passed on to the API query to GBIF as they don't allow that, but we filter out the columns before we give the data back to you.
occ_search(scientificName = "Ursus americanus", fields=c('name','basisOfRecord','protocol'), limit = 20)
Most parameters are vectorized, so you can pass in more than one value:
splist <- c('Cyanocitta stelleri', 'Junco hyemalis', 'Aix sponsa') keys <- sapply(splist, function(x) name_suggest(x)$key, USE.NAMES=FALSE) occ_search(taxonKey=keys, limit=5)
Using thet GBIF map web tile service, making a raster and visualizing it.
x <- map_fetch(taxonKey = 2480498, year = 2000:2017) library(raster) plot(x)