UPDATE: In response to Jarrett’s query I laid out a separate use case in which you may want to query by higher taxonomic rankings than species. See below. In addition, added examples of querying by location in reply to comments by seminym.
We have been working on an R package to get GBIF data from R, with the stable version available through CRAN here, and the development version available on GitHub here.
We had a Google Summer of code stuent work on the package this summer - you can see his work on the package over at his GitHub page here. We have added some new functionality since his work, and would like to show it off.
Lets install rgbif first.
1
2
3
4
5
6
7
# install_github('rgbif', 'ropensci') # uncomment if not already installedlibrary(rgbif)library(plyr)library(XML)library(httr)library(maps)library(ggplot2)
Get taxonomic information on a specific taxon or taxa in GBIF by their taxon concept keys.
1
(keys<-taxonsearch(scientificname="Puma concolor"))# many matches to this search
taxonget(keys[[1]])# let's get the first one - the first row in the data.frame is the one we searched for (51780668)
[[1]]
sciname taxonconceptkeys rank
1 Puma concolor 51780668 species
2 Puma 51780667 genus
3 Felidae 51780651 family
4 Carnivora 51780613 order
5 Mammalia 51780547 class
6 Chordata 51775774 phylum
7 Animalia 51775773 kingdom
8 Puma concolor californica 51780669 subspecies
9 Puma concolor improcera 51780670 subspecies
The occurrencedensity function was renamed to densitylist because it is in the density API service, not the occurrence API service. You can use densitylist to get a data.frame of total occurrence counts by one-degree cell for a single taxon, country, dataset, data publisher or data network. Just a quick reminder of what the function can do:
# density_spplist(originisocountrycode = 'CO', spplist = 'r') # can# abbreviate the `spplist` argument# Get a species list by cell, choosing the one with the greatest no. of# recordsdensity_spplist(originisocountrycode="CO",spplist="great")[1:10]# great is abbreviated from `greatest`
# Can also get a data.frame with counts instead of the species listdensity_spplist(originisocountrycode="CO",spplist="great",listcount="counts")[1:10,]
You can now map point results, from fxns occurrencelist and those from densitylist, which plots them as points or as tiles, respectively. Point map, using output from occurrencelist.
1
2
3
out<-occurrencelist(scientificname="Puma concolor",coordinatestatus=TRUE,maxresults=100,latlongdf=T)gbifmap(input=out)# make a map, plotting on world map
Point map, using output from occurrencelist, with many species plotted as different colors
Tile map, using output from densitylist, using results in Canada only.
1
2
out2<-densitylist(originisocountrycode="CA")# data for Canadagbifmap(out2)# on world map
1
gbifmap(out2,region="Canada")# on Canada map
We can also query by higher taxonomic rankings, and map all lower species within that ranking. Above we queried by scientificname, but we can also query by higher taxonomy. 7071443 is the taxonconceptkey for ‘Bacillariophyceae’, a Class which includes many lower species.
seminym asked about querying by area. You can query by area, though slightly differently for occurrencelist and densitylist functions. For occurrencelist you can search using min and max lat and long values (and min an max altitude, pretty cool, eh).
1
2
3
4
5
6
# Get occurrences or density by area, using min/max lat/long coordinatesout<-occurrencelist(minlatitude=30,maxlatitude=35,minlongitude=-100,maxlongitude=-95,coordinatestatus=T,maxresults=5000,latlongdf=T)# Using `geom_point`gbifmap(out,"state","texas",geom_point)
1
2
# Using geom_jitter to move the points apart from one anothergbifmap(out,"state","texas",geom_jitter,position_jitter(width=0.3,height=0.3))
1
2
# And move points a lotgbifmap(out,"state","texas",geom_jitter,position_jitter(width=1,height=1))
And you can query by area in densitylist by specifying a place using the originisocountrycode argument (as done in an above example). Just showing the head of the data.frame here.
1
2
3
# Get density by place, note that you can't use the lat and long arguments# in densitylisthead(densitylist(originisocountrycode="CA"))