Processing and visualizing OBIS data using R
Installing R and RStudio
See our Introduction to R.
Installing the OBIS R package
install.packages("devtools")
devtools::install_github("iobis/robis")
require(robis)
Retrieving OBIS data
The OBIS R package is documented on GitHub. The scripts used in this section can be found here.
To retrieve occurrence data, use the occurrence function:
require(robis)
data <- occurrence("Abra nitida")
Creating maps
Simple map
The data retrieved before can easily be visualized using a Leaflet map:
require(leaflet)
leaflet() %>%
addTiles("http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}") %>%
addCircleMarkers(data = data.frame(lat = data$decimalLatitude, lng = data$decimalLongitude), radius = 3.5, weight = 0, fillOpacity = 1, fillColor = "#cc3300")

Quality flags
The data retrieved using the R package include the OBIS quality flags. The example below visualizes one of these flags for the European sea sturgeon. It also adds popups to the Leaflet map:
sturgeon_data <- occurrence("Acipenser sturio")
sturgeon_data$qcnum <- qcflags(sturgeon_data$qc, c(28))
colors <- c("#ee3300", "#86b300")[sturgeon_data$qcnum + 1]
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addCircleMarkers(popup = paste0(sturgeon_data$datasetName, "<br/>", sturgeon_data$catalogNumber, "<br/><a href=\"http://www.iobis.org/explore/#/dataset/", sturgeon_data$resourceID, "\">OBIS dataset page</a>"), data = data.frame(lat = sturgeon_data$decimalLatitude, lng = sturgeon_data$decimalLongitude), radius = 3.5, weight = 0, fillColor = colors, fillOpacity = 1)
Datasets
To get all data for a dataset, use the resourceid parameter:
ices_data <- occurrence(resourceid = 1575)
ices_data <- ices_data[20000:30000,]
ices_data$qcnum <- qcflags(ices_data$qc, c(27, 29))
colors <- c("#ee3300", "#ff9900", "#86b300")[ices_data$qcnum + 1]
leaflet() %>%
addTiles("http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png") %>%
addCircleMarkers(popup = ices_data$scientificName, data = data.frame(lat = ices_data$decimalLatitude, lng = ices_data$decimalLongitude), radius = 3.5, weight = 0, fillColor = colors, fillOpacity = 1)
Multiple species
In the next example, data is retrieved for two cod species. For one of them, only one year’s worth of data is retrieved.
pac_data <- occurrence("Gadus macrocephalus")
atl_data <- occurrence("Gadus morhua", year = 2011)
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addCircleMarkers(data = data.frame(lat = pac_data$decimalLatitude, lng = pac_data$decimalLongitude), radius = 3.5, weight = 0, fillOpacity = 1, fillColor = "#ff0066") %>%
addCircleMarkers(data = data.frame(lat = atl_data$decimalLatitude, lng = atl_data$decimalLongitude), radius = 3.5, weight = 0, fillOpacity = 1, fillColor = "#0099cc")
Depth
In this final example, the collection depth of the cod species data is visualized.
require(dplyr)
cod_data <- rbind(
atl_data %>% filter(!is.na(minimumDepthInMeters)) %>% select(decimalLongitude, decimalLatitude, scientificName, minimumDepthInMeters),
pac_data %>% filter(!is.na(minimumDepthInMeters)) %>% select(decimalLongitude, decimalLatitude, scientificName, minimumDepthInMeters)
)
pal <- colorNumeric(palette = "Spectral", domain = -cod_data$minimumDepthInMeters, na.color = "#eeeeee")
colors <- pal(-cod_data$minimumDepthInMeters)
leaflet() %>%
addTiles("http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}") %>%
addCircleMarkers(data = data.frame(lat = cod_data$decimalLatitude, lng = cod_data$decimalLongitude), radius = 3.5, weight = 0, fillOpacity = 1, fillColor = colors)






