BIEN

As a side project I recently helped a friend use an R package for retrieving data from the Botantical Information and Ecology Network Database (BIEN). The code for that exploration is documented below.

install.packages("BIEN")
install.packages("dplyr")
install.packages("leaflet")
install.packages("rgdal")
install.packages("geojsonio")
install.packages("htmltools")
install.packages("knitr")
library(BIEN)
library(leaflet)
library(rgdal)
library(geojsonio)
library(dplyr)
library(htmltools)
library(knitr)

Occurrence

BIEN includes occurence data on the species level. The code below queries the database for Western Sumac (Rhus copallanium) and returns an interactive map with markers for all of the places where the species has been documented.

# retrieve occurrenc data for western sumac
wsumac <- BIEN_occurrence_species(species = "Rhus copallinum")

# plot points on map
# popups for date collected where available
leaflet(data = wsumac) %>%
  addProviderTiles("OpenStreetMap.BlackAndWhite") %>%
  addCircleMarkers(lng=wsumac$longitude, 
                   lat=wsumac$latitude,
                   col="firebrick",
                   stroke = FALSE,
                   opacity = 0.1,
                   label = ~htmlEscape(date_collected))

Ranges

The ranges for species are also available in the database. These are included as shp files that can be pretty easily dropped on a map.

# retrieve range data as shp files 
BIEN_ranges_species("Rhus copallinum", directory = "shp")
##           Species Range_map_downloaded?
## 1 Rhus_copallinum                   Yes
# read in the data
wsumac <- readOGR(dsn = path.expand("shp"))
## OGR data source with driver: ESRI Shapefile 
## Source: "/Users/pnagraj/VP/nagraj-dot-net/content/notes/shp", layer: "Rhus_copallinum"
## with 1 features
## It has 1 fields
# plot the range
leaflet(data = wsumac) %>%
  addProviderTiles("OpenStreetMap.BlackAndWhite") %>%
  addPolygons()

Traits

In terms of metadata, BIEN provides trait information. In the example below, these were measured multiple times and averaged to be reported in a table.

# read in trait data
wsumac_traits <- BIEN_trait_species("Rhus copallinum")

# aggregate and average numeric traits
summarised <-
  wsumac_traits %>%
  group_by(trait_name, unit) %>%
  summarise(average = mean(as.numeric(trait_value), na.rm = TRUE)) %>%
  filter(!is.nan(average)) %>%
  mutate(average = paste(round(average, 2), unit)) %>%
  select(-unit)

kable(summarised)

States

BIEN has species lists on state level as well. After retrieving lists of species for each of the states in the USA … we can count the number of species, and map the distribution of counts by State. This might provide a visual idea of plant diversity across the country.

# by states
# query BIEN for lists of species
state_species <- BIEN_list_state(country="United States", state=state.name)

# count up number of species by state
nspecies <- 
  state_species %>%
  group_by(state_province) %>%
  tally()

# get data for map
json_api <- "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json"
states <- geojson_read(json_api, what = "sp")

# join in species count
states@data <-
  states@data %>%
  inner_join(nspecies, by = c("name" = "state_province")) %>%
  rename(count = n)

pal <- colorNumeric("plasma", domain = states@data$count)

leaflet(states) %>%
  addProviderTiles("OpenStreetMap.BlackAndWhite") %>%
  addPolygons(color = ~pal(count),
              stroke = FALSE,
              label = as.character(states@data$count)) %>%
  addLegend(pal = pal, 
            values = ~count,
            position = "topright",
            labFormat = labelFormat(digits = 0)) %>%
  setView(lat = 37, lng = -90, zoom = 3)

Related