Introduction to spoccutils

Load spocc and spoccutils

library("spocc")
library("spoccutils")

Interactive maps

Leaflet.js

Leaflet JS is an open source mapping library that can leverage various layers from multiple sources. Using the leafletR library, it's possible to generate a local geoJSON file and a html file of species distribution maps. The folder can easily be moved to a web server and served widely without any additional coding.

Here is an example of making a leaflet map:

spp <- c('Danaus plexippus','Accipiter striatus','Pinus contorta')
dat <- occ(query = spp, from = 'gbif', has_coords = TRUE, limit = 100)
map_leaflet(dat, dest = ".")

leaflet

Geojson map as a Github gist

You can also create interactive maps via the mapgist function. You have to have a Github account to use this function. Github accounts are free though, and great for versioning and collaborating on code or papers. When you run the mapgist function it will ask for your Github username and password. You can alternatively store those in your .Rprofile file by adding entries for username (options(github.username = 'username')) and password (options(github.password = 'password')).

spp <- c('Danaus plexippus', 'Accipiter striatus', 'Pinus contorta')
dat <- occ(query = spp, from = 'gbif', has_coords = TRUE, limit = 100)
dat <- fixnames(dat)
map_gist(dat, color = c("#976AAE", "#6B944D", "#BD5945"))

gist

Static maps

base plots

Base plots, or the built in plotting facility in R accessed via plot(), is quite fast, but not easy or efficient to use, but are good for a quick glance at some data.

spnames <- c('Accipiter striatus', 'Setophaga caerulescens', 'Spinus tristis')
out <- occ(query = spnames, from = 'gbif', has_coords = TRUE, limit = 100)
map_plot(out, cex = 1, pch = 10)

plot of chunk unnamed-chunk-5

ggplot2

ggplot2 is a powerful package for making visualizations in R. Read more about it here. We created a simple wrapper function mapggplot to make a ggplot2 map from occurrence data using the ggmap package, which is built on top of ggplot2. Here's an example:

dat <- occ(query = 'Lynx rufus californicus', from = 'ecoengine', has_coords = TRUE, limit = 200)
map_ggplot(dat, map = "usa")

plot of chunk unnamed-chunk-6

ggmap

map_ggmap(dat)

plot of chunk unnamed-chunk-7