rgbif gives you access to data from GBIF via their REST API. GBIF versions their API - we are currently using v1 of their API. You can no longer use their old API in this package - see ?rgbif-defunct.

To get started, see:

  • rgbif vignette: an introduction to the package’s main functionalities.
  • Function reference: an overview of all rgbif functions.
  • Articles: vignettes/tutorials on how to download data, clean data, and work with taxonomic names.
  • Occurrence manual: a book covering a suite of R packages used for working with biological occurrence data.

Check out the rgbif paper for more information on this package and the sister Python and Ruby clients.

Package API

The rgbif package API follows the GBIF API, which has the following sections:

Installation

Alternatively, install development version

install.packages("devtools")
devtools::install_github("ropensci/rgbif")
library("rgbif")

Note: Windows users have to first install Rtools to use devtools

Mac Users: (in case of errors)

Terminal:

Install gdal : https://github.com/edzer/sfr/blob/master/README.md#macos

brew install openssl

in R:

Search for occurrence data

occ_search(scientificName = "Ursus americanus", limit = 50)
#> Records found [12622] 
#> Records returned [50] 
#> No. unique hierarchies [1] 
#> No. media records [50] 
#> No. facets [0] 
#> Args [limit=50, offset=0, scientificName=Ursus americanus, fields=all] 
#> # A tibble: 50 x 74
#>    key   scientificName decimalLatitude decimalLongitude issues datasetKey
#>    <chr> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#>  1 1990… Ursus america…            44.9            -62.7 cdrou… 50c9509d-…
#>  2 1990… Ursus america…            40.9           -121.  gass84 50c9509d-…
#>  3 2006… Ursus america…            31.5           -110.  cdrou… 50c9509d-…
#>  4 1986… Ursus america…            30.1           -103.  cdrou… 50c9509d-…
#>  5 1990… Ursus america…            45.4            -93.2 cdrou… 50c9509d-…
#>  6 1990… Ursus america…            35.7            -76.6 cdrou… 50c9509d-…
#>  7 1990… Ursus america…            33.1            -91.9 cdrou… 50c9509d-…
#>  8 1990… Ursus america…            35.6            -82.9 cdrou… 50c9509d-…
#>  9 1990… Ursus america…            29.2            -81.8 cdrou… 50c9509d-…
#> 10 1990… Ursus america…            45.4            -93.1 cdrou… 50c9509d-…
#> # … with 40 more rows, and 68 more variables: publishingOrgKey <chr>,
#> #   networkKeys <chr>, installationKey <chr>, publishingCountry <chr>,
#> #   protocol <chr>, lastCrawled <chr>, lastParsed <chr>, crawlId <int>,
#> #   extensions <chr>, basisOfRecord <chr>, taxonKey <int>,
#> #   kingdomKey <int>, phylumKey <int>, classKey <int>, orderKey <int>,
#> #   familyKey <int>, genusKey <int>, speciesKey <int>,
#> #   acceptedTaxonKey <int>, acceptedScientificName <chr>, kingdom <chr>,
#> #   phylum <chr>, order <chr>, family <chr>, genus <chr>, species <chr>,
#> #   genericName <chr>, specificEpithet <chr>, taxonRank <chr>,
#> #   taxonomicStatus <chr>, dateIdentified <chr>,
#> #   coordinateUncertaintyInMeters <dbl>, stateProvince <chr>, year <int>,
#> #   month <int>, day <int>, eventDate <chr>, modified <chr>,
#> #   lastInterpreted <chr>, references <chr>, license <chr>,
#> #   identifiers <chr>, facts <chr>, relations <chr>, geodeticDatum <chr>,
#> #   class <chr>, countryCode <chr>, country <chr>, rightsHolder <chr>,
#> #   identifier <chr>, verbatimEventDate <chr>, datasetName <chr>,
#> #   verbatimLocality <chr>, gbifID <chr>, collectionCode <chr>,
#> #   occurrenceID <chr>, taxonID <chr>, catalogNumber <chr>,
#> #   recordedBy <chr>, http...unknown.org.occurrenceDetails <chr>,
#> #   institutionCode <chr>, rights <chr>, eventTime <chr>,
#> #   identificationID <chr>, name <chr>, infraspecificEpithet <chr>,
#> #   informationWithheld <chr>, occurrenceRemarks <chr>

Or you can get the taxon key first with name_backbone(). Here, we select to only return the occurrence data.

key <- name_backbone(name='Helianthus annuus', kingdom='plants')$speciesKey
occ_search(taxonKey=key, limit=20)
#> Records found [43741] 
#> Records returned [20] 
#> No. unique hierarchies [1] 
#> No. media records [14] 
#> No. facets [0] 
#> Args [limit=20, offset=0, taxonKey=9206251, fields=all] 
#> # A tibble: 20 x 92
#>    key   scientificName decimalLatitude decimalLongitude issues datasetKey
#>    <chr> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#>  1 1993… Helianthus an…            33.4          -118.   cdrou… 50c9509d-…
#>  2 1986… Helianthus an…            33.8          -118.   cdrou… 50c9509d-…
#>  3 1990… Helianthus an…            53.9            10.9  cdrou… 6ac3f774-…
#>  4 2247… Helianthus an…            55.7            14.2  gass84 38b4c89f-…
#>  5 1990… Helianthus an…            52.6            10.1  cdrou… 6ac3f774-…
#>  6 2235… Helianthus an…            51.2             4.45 ""     7f5e4129-…
#>  7 1993… Helianthus an…            34.0          -117.   cdrou… 50c9509d-…
#>  8 2247… Helianthus an…            58.4            11.9  cdrou… 38b4c89f-…
#>  9 2236… Helianthus an…            26.2           -98.2  cdrou… 50c9509d-…
#> 10 1986… Helianthus an…            27.7           -97.3  cdrou… 50c9509d-…
#> 11 1990… Helianthus an…            26.2           -98.2  cdrou… 50c9509d-…
#> 12 2006… Helianthus an…            27.7           -97.3  cdrou… 50c9509d-…
#> 13 2005… Helianthus an…            27.5           -99.5  cdrou… 50c9509d-…
#> 14 2247… Helianthus an…            57.6            11.9  gass84 38b4c89f-…
#> 15 2013… Helianthus an…            25.5          -108.   cdrou… 50c9509d-…
#> 16 1993… Helianthus an…            29.8           -95.2  cdrou… 50c9509d-…
#> 17 2012… Helianthus an…            33.5          -118.   cdrou… 50c9509d-…
#> 18 2247… Helianthus an…            58.4            11.9  cdrou… 38b4c89f-…
#> 19 2006… Helianthus an…            34.6            33.0  cdrou… 50c9509d-…
#> 20 2005… Helianthus an…            31.6          -106.   cdrou… 50c9509d-…
#> # … with 86 more variables: publishingOrgKey <chr>, networkKeys <chr>,
#> #   installationKey <chr>, publishingCountry <chr>, protocol <chr>,
#> #   lastCrawled <chr>, lastParsed <chr>, crawlId <int>, extensions <chr>,
#> #   basisOfRecord <chr>, taxonKey <int>, kingdomKey <int>,
#> #   phylumKey <int>, classKey <int>, orderKey <int>, familyKey <int>,
#> #   genusKey <int>, speciesKey <int>, acceptedTaxonKey <int>,
#> #   acceptedScientificName <chr>, kingdom <chr>, phylum <chr>,
#> #   order <chr>, family <chr>, genus <chr>, species <chr>,
#> #   genericName <chr>, specificEpithet <chr>, taxonRank <chr>,
#> #   taxonomicStatus <chr>, dateIdentified <chr>,
#> #   coordinateUncertaintyInMeters <dbl>, stateProvince <chr>, year <int>,
#> #   month <int>, day <int>, eventDate <chr>, modified <chr>,
#> #   lastInterpreted <chr>, references <chr>, license <chr>,
#> #   identifiers <chr>, facts <chr>, relations <chr>, geodeticDatum <chr>,
#> #   class <chr>, countryCode <chr>, country <chr>, rightsHolder <chr>,
#> #   identifier <chr>, verbatimEventDate <chr>, datasetName <chr>,
#> #   verbatimLocality <chr>, gbifID <chr>, collectionCode <chr>,
#> #   occurrenceID <chr>, taxonID <chr>, catalogNumber <chr>,
#> #   recordedBy <chr>, http...unknown.org.occurrenceDetails <chr>,
#> #   institutionCode <chr>, rights <chr>, eventTime <chr>,
#> #   occurrenceRemarks <chr>, identificationID <chr>, name <chr>,
#> #   locality <chr>, continent <chr>, county <chr>, municipality <chr>,
#> #   identificationVerificationStatus <chr>, language <chr>, type <chr>,
#> #   occurrenceStatus <chr>, vernacularName <chr>, taxonConceptID <chr>,
#> #   informationWithheld <chr>, endDayOfYear <chr>, startDayOfYear <chr>,
#> #   datasetID <chr>, accessRights <chr>, higherClassification <chr>,
#> #   individualCount <int>, nomenclaturalCode <chr>,
#> #   samplingProtocol <chr>, reproductiveCondition <chr>

Search for many species

Get the keys first with name_backbone(), then pass to occ_search()

splist <- c('Accipiter erythronemius', 'Junco hyemalis', 'Aix sponsa')
keys <- sapply(splist, function(x) name_backbone(name=x)$speciesKey, USE.NAMES=FALSE)
occ_search(taxonKey=keys, limit=5, hasCoordinate=TRUE)
#> Occ. found [2480598 (30), 9362842 (5522815), 2498387 (1824388)] 
#> Occ. returned [2480598 (5), 9362842 (5), 2498387 (5)] 
#> No. unique hierarchies [2480598 (1), 9362842 (1), 2498387 (1)] 
#> No. media records [2480598 (5), 9362842 (5), 2498387 (5)] 
#> No. facets [2480598 (0), 9362842 (0), 2498387 (0)] 
#> Args [hasCoordinate=TRUE, limit=5, offset=0,
#>      taxonKey=2480598,9362842,2498387, fields=all] 
#> 3 requests; First 10 rows of data from 2480598
#> 
#> # A tibble: 5 x 68
#>   key   scientificName decimalLatitude decimalLongitude issues datasetKey
#>   <chr> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#> 1 2243… Accipiter ery…           -38.3            -60.4 ""     b1047888-…
#> 2 2243… Accipiter ery…           -24.3            -48.4 ""     b1047888-…
#> 3 2243… Accipiter ery…           -26.3            -48.6 ""     b1047888-…
#> 4 2243… Accipiter ery…           -26.3            -48.6 txmat… b1047888-…
#> 5 2243… Accipiter ery…           -22.4            -42.9 ""     b1047888-…
#> # … with 62 more variables: publishingOrgKey <chr>, networkKeys <chr>,
#> #   installationKey <chr>, publishingCountry <chr>, protocol <chr>,
#> #   lastCrawled <chr>, lastParsed <chr>, crawlId <int>, extensions <chr>,
#> #   basisOfRecord <chr>, taxonKey <int>, kingdomKey <int>,
#> #   phylumKey <int>, classKey <int>, orderKey <int>, familyKey <int>,
#> #   genusKey <int>, speciesKey <int>, acceptedTaxonKey <int>,
#> #   acceptedScientificName <chr>, kingdom <chr>, phylum <chr>,
#> #   order <chr>, family <chr>, genus <chr>, species <chr>,
#> #   genericName <chr>, specificEpithet <chr>, taxonRank <chr>,
#> #   taxonomicStatus <chr>, year <int>, month <int>, day <int>,
#> #   eventDate <chr>, lastInterpreted <chr>, references <chr>,
#> #   license <chr>, identifiers <chr>, facts <chr>, relations <chr>,
#> #   geodeticDatum <chr>, class <chr>, countryCode <chr>, country <chr>,
#> #   rightsHolder <chr>, identifier <chr>, verbatimEventDate <chr>,
#> #   nomenclaturalCode <chr>, locality <chr>, gbifID <chr>,
#> #   collectionCode <chr>, occurrenceID <chr>, catalogNumber <chr>,
#> #   recordedBy <chr>, vernacularName <chr>, fieldNotes <chr>,
#> #   eventTime <chr>, behavior <chr>, verbatimElevation <chr>,
#> #   higherClassification <chr>, name <chr>, associatedTaxa <chr>

Maps

We’ve removed gbifmap() which helped users plot data from functions occ_search()/occ_data() - instead we strongly recommend using our other package mapr.

As of rgibf v1, we have integration for GBIF’s mapping API, which lets you get raster images of occurrences of taxa of interest. For example:

library(raster)
plot(x, axes = FALSE, box = FALSE)
Example map

Example map

Screencast

Meta


This package is part of a richer suite called spocc - Species Occurrence Data, along with several other packages, that provide access to occurrence records from multiple databases.


rofooter