rgbif vignette - 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 the BISON database from R.


Install rgbif

# install.packages("devtools"); library(devtools); install_github("rbison", "ropensci")
library(rgbif); library(XML); library(RCurl); library(plyr); library(ggplot2); library(maps)

Get a list of the data networks in GBIF - and you can use the networkkey number to seach for occurrences for the specific provider in other functions

# Test the function for a few networks
networks(maxresults=5)

# By name
networks('ORNIS')

Get a list of the data providers in GBIF - and you can use the dataproviderkey number to seach for occurrences for the specific provider in other functions

# Test the function for a few providers
providers(maxresults=5)

# By data provider name
providers('University of Texas-Austin')

Get a list of the data resources in GBIF - and you can use the resourcekey number to seach for occurrences for the specific resource in other functions

# Test the function for a few resources
resources(maxresults=5)

# By name
head(resources('Flora'))

Get number of occurrences for a set of search parameters

occurrencecount(scientificname = 'Accipiter erythronemius', coordinatestatus = TRUE)
occurrencecount(scientificname = 'Helianthus annuus', coordinatestatus = TRUE, year=2005, maxlatitude=20)

Get possible values to be used in taxonomic rank arguments in functions

taxrank()

Seach by taxon to retrieve number of records per taxon found in GBIF

taxoncount(scientificname = 'Puma concolor')
taxoncount(scientificname = 'Helianthus annuus')
taxoncount(rank = 'family')

Get taxonomic information on a specific taxon or taxa in GBIF by their taxon concept keys

(out <- taxonsearch(scientificname = 'Puma concolor'))

Search for taxa in GBIF

taxonsearch(scientificname = 'Puma concolor', rank="species", maxresults=10)
taxonsearch(scientificname = 'Puma concolor', rank="species", dataproviderkey=1)

Get data for a single occurrence. Note that data is returned as a list, so you have to convert to a data.frame, etc. as you wish

occurrenceget(key = 13749100)$dataProvider$dataResources$dataResource$occurrenceRecords$TaxonOccurrence[1:10]

out <- occurrencelist(scientificname = 'Puma concolor', coordinatestatus=TRUE, maxresults=20)

Note that the default object printed from a call to occurrencelist is a list that contains:

out

Where do you get data after a call to the occurrencelist function? This is where gbifdata comes in. By default a call to gbifdata prints a minimal data.frame with just rows name, latitude, and longitude.

gbifdata(out)

Though you can get more detailed data by calling minimal=FALSE.

head( gbifdata(out, minimal=FALSE)[,1:6] )

And you can get all possible data by specifying format=darwin.

out <- occurrencelist(scientificname = 'Puma concolor', coordinatestatus=TRUE, format="darwin", maxresults=20)
head( gbifdata(out, minimal=FALSE)[,1:6] )

Maps

splist <- c('Accipiter erythronemius', 'Junco hyemalis', 'Aix sponsa', 'Ceyx fallax', 'Picoides lignarius', 'Campephilus leucopogon')
out <- occurrencelist_many(splist, coordinatestatus = TRUE, maxresults = 20)
gbifmap_list(out)

Another example, setting scientificname="*" so we just get any species, and then mapping points only within the state of Texas in the US.

out <- occurrencelist(scientificname="*", minlatitude=30, maxlatitude=35, minlongitude=-100, maxlongitude=-95, coordinatestatus = TRUE, maxresults = 200)
gbifmap_list(input=out, mapdatabase="state", region="texas", geom=geom_jitter, jitter=position_jitter(width = 0.3, height = 0.3))



ropensci/spoccutils documentation built on Sept. 12, 2022, 3:03 p.m.