Chapter 4 rgbif

4.1 What is rgbif?

rgbif is an R package that interfaces with the GBIF (Global Biodiversity Information Facility) API (Application Programming Interface).

rgbif has the following methods

  • registry (https://www.gbif.org/developer/registry) - Metadata on datasets, and contributing organizations, installations, networks, and nodes
    • rgbif functions: dataset_metrics(), dataset_search(), dataset_suggest(), datasets(), enumeration(), enumeration_country(), installations(), networks(), nodes(), organizations()
    • Registry also includes the GBIF OAI-PMH service, which includes GBIF registry data only. rgbif functions: gbif_oai_get_records(), gbif_oai_identify(), gbif_oai_list_identifiers(), gbif_oai_list_metadataformats(), gbif_oai_list_records(), gbif_oai_list_sets()
  • species (https://www.gbif.org/developer/species) - Species names and metadata
    • rgbif functions: name_backbone(), name_lookup(), name_suggest(), name_usage()
  • occurrences (https://www.gbif.org/developer/occurrence) - Occurrences, both for the search and download APIs
    • rgbif functions: occ_count(), occ_data(), occ_download(), occ_download_cancel(), occ_download_cancel_staged(), occ_download_get(), occ_download_import(), occ_download_list(), occ_download_meta(), occ_get(), occ_issues(), occ_issues_lookup(), occ_metadata(), occ_search()
  • maps (https://www.gbif.org/developer/maps) - Map API
    • rgbif functions: map_fetch()
    • Note: we used to have a function gbifmap() that used ggplot2 to plot data from the occurrence API, but it’s been removed - see package [mapr][]

4.2 Basic example

Load rgbif xxx

library(rgbif)
splist <- c('Accipiter erythronemius', 'Junco hyemalis', 'Aix sponsa')
keys <- vapply(splist, function(x) name_backbone(name = x)$speciesKey, integer(1))
occ_search(taxonKey = keys, limit = 5, hasCoordinate = TRUE)
#> Records found [2480598 (61), 9362842 (6384090), 2498387 (2218621)] 
#> Records 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 104
#>   key   scientificName decimalLatitude decimalLongitude issues datasetKey
#>   <chr> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#> 1 2243… Accipiter ery…           -38.3            -60.4 colma… b1047888-…
#> 2 2432… Accipiter ery…           -24.0            -52.2 colma… b1047888-…
#> 3 2837… Accipiter ery…           -22.3            -42.6 cdrou… 8a863029-…
#> 4 2609… Accipiter ery…           -26.6            -53.8 colma… b1047888-…
#> 5 2609… Accipiter ery…           -26.6            -53.8 colma… b1047888-…
#> # … with 98 more variables: publishingOrgKey <chr>, installationKey <chr>,
#> #   publishingCountry <chr>, protocol <chr>, lastCrawled <chr>,
#> #   lastParsed <chr>, crawlId <int>, hostingOrganizationKey <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...rs.tdwg.org.ac.terms.resourceCreationTechnique <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.format <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.elements.1.1.creator <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...rs.tdwg.org.ac.terms.variantLiteral <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.identifier <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...ns.adobe.com.xap.1.0.Rating <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.description <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.elements.1.1.type <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...rs.tdwg.org.ac.terms.accessURI <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.rights <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...ns.adobe.com.xap.1.0.rights.Owner <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.format.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.elements.1.1.creator.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...rs.tdwg.org.ac.terms.variantLiteral.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.identifier.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.elements.1.1.type.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...rs.tdwg.org.ac.terms.accessURI.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...rs.tdwg.org.ac.terms.caption <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...purl.org.dc.terms.rights.1 <chr>,
#> #   extensions.http...rs.tdwg.org.ac.terms.Multimedia.http...ns.adobe.com.xap.1.0.rights.Owner.1 <chr>,
#> #   basisOfRecord <chr>, occurrenceStatus <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>, gadm.level0.gid <chr>, gadm.level0.name <chr>,
#> #   gadm.level1.gid <chr>, gadm.level1.name <chr>, gadm.level2.gid <chr>,
#> #   gadm.level2.name <chr>, isInCluster <lgl>, geodeticDatum <chr>,
#> #   class <chr>, countryCode <chr>, recordedByIDs <chr>, identifiedByIDs <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>, verbatimElevation <chr>, behavior <chr>,
#> #   higherClassification <chr>, name <chr>, gadm.level3.gid <chr>,
#> #   gadm.level3.name <chr>, extensions <chr>, individualCount <int>,
#> #   lifeStage <chr>, coordinateUncertaintyInMeters <dbl>, continent <chr>,
#> #   modified <chr>