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.

Get rgbif

Install from CRAN

Or install the development version from GitHub

devtools::install_github("ropensci/rgbif")

Load rgbif

library("rgbif")

Number of occurrences

Search by type of record, all observational in this case

occ_count(basisOfRecord='OBSERVATION')
#> [1] 19756387

Records for Puma concolor with lat/long data (georeferened) only. Note that hasCoordinate in occ_search() is the same as georeferenced in occ_count().

occ_count(taxonKey=2435099, georeferenced=TRUE)
#> [1] 4628

All georeferenced records in GBIF

occ_count(georeferenced=TRUE)
#> [1] 991539311

Records from Denmark

denmark_code <- isocodes[grep("Denmark", isocodes$name), "code"]
occ_count(country=denmark_code)
#> [1] 29429637

Number of records in a particular dataset

occ_count(datasetKey='9e7ea106-0bf8-4087-bb61-dfe4f29e0f17')
#> [1] 4591

All records from 2012

Records for a particular dataset, and only for preserved specimens

occ_count(datasetKey='e707e6da-e143-445d-b41d-529c4a777e8b', basisOfRecord='OBSERVATION')
#> [1] 0

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.

By default 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

Search for the class mammalia

Look up the species Helianthus annuus

The function name_usage() works with lots of different name endpoints in GBIF, listed at http://www.gbif.org/developer/species#nameUsages.

The function name_backbone() is used to search against the GBIF backbone taxonomy

The function name_suggest() is optimized for speed, and gives back suggested names based on query parameters.

Single occurrence records

Get data for a single occurrence. Note that data is returned as a list, with slots for metadata and data, or as a hierarchy, or just data.

Just data

Just taxonomic hierarchy

All data, or leave return parameter blank

Get many occurrences. occ_get is vectorized

Search for occurrences

By default 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)
#> Records found [12042] 
#> Records returned [20] 
#> No. unique hierarchies [1] 
#> No. media records [20] 
#> No. facets [0] 
#> Args [limit=20, offset=0, scientificName=Ursus americanus, fields=all] 
#> # A tibble: 20 x 74
#>       key scientificName decimalLatitude decimalLongitude issues datasetKey
#>     <int> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#>  1 1.99e9 Ursus america…            29.2            -81.8 cdrou… 50c9509d-…
#>  2 1.99e9 Ursus america…            45.3            -76.8 cdrou… 50c9509d-…
#>  3 1.99e9 Ursus america…            47.7           -122.  cdrou… 50c9509d-…
#>  4 1.99e9 Ursus america…            32.6           -109.  cdrou… 50c9509d-…
#>  5 1.99e9 Ursus america…            33.1            -91.9 cdrou… 50c9509d-…
#>  6 1.99e9 Ursus america…            27.7            -81.5 gass84 50c9509d-…
#>  7 1.99e9 Ursus america…            30.1           -103.  cdrou… 50c9509d-…
#>  8 1.99e9 Ursus america…            39.4           -120.  cdrou… 50c9509d-…
#>  9 1.99e9 Ursus america…            35.7            -76.6 cdrou… 50c9509d-…
#> 10 1.99e9 Ursus america…            33.1            -91.9 cdrou… 50c9509d-…
#> 11 1.99e9 Ursus america…            45.5            -93.1 cdrou… 50c9509d-…
#> 12 1.99e9 Ursus america…            45.4            -93.1 cdrou… 50c9509d-…
#> 13 1.99e9 Ursus america…            31.9            -94.7 cdrou… 50c9509d-…
#> 14 1.99e9 Ursus america…            45.4            -93.2 cdrou… 50c9509d-…
#> 15 1.99e9 Ursus america…            45.4            -93.2 cdrou… 50c9509d-…
#> 16 1.99e9 Ursus america…            44.9            -62.7 cdrou… 50c9509d-…
#> 17 1.99e9 Ursus america…            40.9           -121.  gass84 50c9509d-…
#> 18 1.99e9 Ursus america…            39.0           -120.  cdrou… 50c9509d-…
#> 19 1.99e9 Ursus america…            38.9           -120.  cdrou… 50c9509d-…
#> 20 1.99e9 Ursus america…            35.6            -82.9 cdrou… 50c9509d-…
#> # … with 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>, 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>,
#> #   gbifID <chr>, verbatimLocality <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>,
#> #   coordinateUncertaintyInMeters <dbl>, occurrenceRemarks <chr>,
#> #   infraspecificEpithet <chr>, informationWithheld <chr>

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 occ_search() function:

key <- name_suggest(q='Helianthus annuus', rank='species')$key[1]
occ_search(taxonKey=key, limit=20)
#> Records found [43757] 
#> Records returned [20] 
#> No. unique hierarchies [1] 
#> No. media records [16] 
#> No. facets [0] 
#> Args [limit=20, offset=0, taxonKey=9206251, fields=all] 
#> # A tibble: 20 x 91
#>       key scientificName decimalLatitude decimalLongitude issues datasetKey
#>     <int> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#>  1 1.99e9 Helianthus an…            34.0           -117.  cdrou… 50c9509d-…
#>  2 1.99e9 Helianthus an…            33.4           -118.  cdrou… 50c9509d-…
#>  3 1.99e9 Helianthus an…            33.8           -118.  cdrou… 50c9509d-…
#>  4 1.99e9 Helianthus an…            53.9             10.9 cdrou… 6ac3f774-…
#>  5 1.99e9 Helianthus an…            27.7            -97.3 cdrou… 50c9509d-…
#>  6 1.99e9 Helianthus an…            52.6             10.1 cdrou… 6ac3f774-…
#>  7 1.99e9 Helianthus an…            26.2            -98.2 cdrou… 50c9509d-…
#>  8 2.01e9 Helianthus an…            31.5            -97.1 cdrou… 50c9509d-…
#>  9 1.99e9 Helianthus an…            29.8            -95.2 cdrou… 50c9509d-…
#> 10 2.01e9 Helianthus an…            31.6           -106.  cdrou… 50c9509d-…
#> 11 2.01e9 Helianthus an…            27.5            -99.5 cdrou… 50c9509d-…
#> 12 1.95e9 Helianthus an…           -37.8            175.  gass84 50c9509d-…
#> 13 1.82e9 Helianthus an…            59.8             17.5 gass84 38b4c89f-…
#> 14 1.95e9 Helianthus an…           -37.8            175.  gass84 50c9509d-…
#> 15 1.82e9 Helianthus an…            56.6             16.4 cdrou… 38b4c89f-…
#> 16 1.84e9 Helianthus an…            34.1           -116.  gass84 50c9509d-…
#> 17 1.82e9 Helianthus an…            56.6             16.6 cdrou… 38b4c89f-…
#> 18 1.81e9 Helianthus an…            25.7           -100.  cdrou… 50c9509d-…
#> 19 1.81e9 Helianthus an…            25.6           -100.  cdrou… 50c9509d-…
#> 20 1.84e9 Helianthus an…            33.9           -117.  cdrou… 50c9509d-…
#> # … with 85 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>, 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>,
#> #   gbifID <chr>, verbatimLocality <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>,
#> #   coordinateUncertaintyInMeters <dbl>, occurrenceRemarks <chr>,
#> #   locality <chr>, individualCount <int>, 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>,
#> #   identificationRemarks <chr>, habitat <chr>

Like many functions in rgbif, you can choose what to return with the return parameter, here, just returning 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.

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[1], USE.NAMES=FALSE)
occ_search(taxonKey=keys, limit=5)
#> Occ. found [2482598 (709564), 9362842 (3822355), 2498387 (1248740)] 
#> Occ. returned [2482598 (5), 9362842 (5), 2498387 (5)] 
#> No. unique hierarchies [2482598 (1), 9362842 (1), 2498387 (1)] 
#> No. media records [2482598 (5), 9362842 (5), 2498387 (5)] 
#> No. facets [2482598 (0), 9362842 (0), 2498387 (0)] 
#> Args [limit=5, offset=0, taxonKey=2482598,9362842,2498387, fields=all] 
#> 3 requests; First 10 rows of data from 2482598
#> 
#> # A tibble: 5 x 71
#>      key scientificName decimalLatitude decimalLongitude issues datasetKey
#>    <int> <chr>                    <dbl>            <dbl> <chr>  <chr>     
#> 1 1.99e9 Cyanocitta st…            16.7            -92.7 cdrou… 50c9509d-…
#> 2 1.99e9 Cyanocitta st…            32.9           -106.  cdrou… 50c9509d-…
#> 3 1.99e9 Cyanocitta st…            32.9           -106.  cdrou… 50c9509d-…
#> 4 1.99e9 Cyanocitta st…            32.9           -106.  cdrou… 50c9509d-…
#> 5 1.99e9 Cyanocitta st…            32.9           -106.  cdrou… 50c9509d-…
#> # … with 65 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>,
#> #   gbifID <chr>, verbatimLocality <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>

Maps

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)
plot of chunk gbifmap1

plot of chunk gbifmap1