Package mapr. March 21, 2018

Similar documents
Package mapr. April 11, 2017

Package wikitaxa. December 21, 2017

Package scrubr. August 29, 2016

Package brranching. R topics documented:

Package rbraries. April 18, 2018

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package postgistools

Package spocc. November 15, 2018

Package osrm. November 13, 2017

Package ritis. May 23, 2018

Package nodbi. August 1, 2018

Package datasets.load

Package tiler. June 9, 2018

Package taxizedb. June 21, 2017

Package fastdummies. January 8, 2018

Package jpmesh. December 4, 2017

Package gtrendsr. August 4, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package gtrendsr. October 19, 2017

Package rollply. R topics documented: August 29, Title Moving-Window Add-on for 'plyr' Version 0.5.0

Package spark. July 21, 2017

Package nlgeocoder. October 8, 2018

Package sigmanet. April 23, 2018

Package htmlwidgets. July 10, 2017

Package opencage. January 16, 2018

Package repec. August 31, 2018

Package patentsview. July 12, 2017

Package fitbitscraper

Package robotstxt. November 12, 2017

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package rdryad. June 18, 2018

Package geojson. November 8, 2017

Package githubinstall

Package nngeo. September 29, 2018

Package SEMrushR. November 3, 2018

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package facerec. May 14, 2018

Package available. November 17, 2017

Package zoon. January 27, 2018

Package pdfsearch. July 10, 2018

Package rnrfa. April 13, 2018

Package webmockr. May 23, 2018

Package ECctmc. May 1, 2018

Package calpassapi. August 25, 2018

Package tidyimpute. March 5, 2018

Package comparedf. February 11, 2019

Package messaging. May 27, 2018

Package censusr. R topics documented: June 14, Type Package Title Collect Data from the Census API Version 0.0.

Package kdtools. April 26, 2018

Package geogrid. August 19, 2018

Package TrajDataMining

Package qualmap. R topics documented: September 12, Type Package

Package marinespeed. February 17, 2017

Package lumberjack. R topics documented: July 20, 2018

Package geoops. March 19, 2018

Package censusapi. August 19, 2018

Package internetarchive

Package datapasta. January 24, 2018

Package mapedit. R topics documented: March 2, Title Interactive Editing of Spatial Data in R

Package rmapzen. October 7, 2018

Package dkanr. July 12, 2018

Package tidytransit. March 4, 2019

Package condusco. November 8, 2017

Package rgho. R topics documented: January 18, 2017

Package virustotal. May 1, 2017

Package BiocManager. November 13, 2018

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package gameofthrones

Package reval. May 26, 2015

Package rnaturalearth

Package validara. October 19, 2017

Package goodpractice

Package sankey. R topics documented: October 22, 2017

Package projector. February 27, 2018

Package clipr. June 23, 2018

Package crossword.r. January 19, 2018

Package docxtools. July 6, 2018

Package bigqueryr. October 23, 2017

Package GetITRData. October 22, 2017

Package rpostgislt. March 2, 2018

Package pangaear. January 3, 2018

Package climber. R topics documented:

Package packcircles. April 28, 2018

Package osmdata. February 22, 2018

Package canvasxpress

Package farver. November 20, 2018

Package rzeit2. January 7, 2019

Package RODBCext. July 31, 2017

Package harrypotter. September 3, 2018

Package postal. July 27, 2018

Package fingertipsr. May 25, Type Package Version Title Fingertips Data for Public Health

Package mapsapi. March 12, 2018

Package deductive. June 2, 2017

Package knitrbootstrap

Package weco. May 4, 2018

Package mdftracks. February 6, 2017

Package WordR. September 7, 2017

Package raker. October 10, 2017

Package NFP. November 21, 2016

Package lucid. August 24, 2018

Transcription:

Title Visualize Species Occurrence Data Package mapr March 21, 2018 Utilities for visualizing species occurrence data. Includes functions to visualize occurrence data from 'spocc', 'rgbif', and other packages. Mapping options included for base R plots, 'ggplot2', 'ggmap', 'leaflet' and 'GitHub' 'gists'. Version 0.4.0 License MIT + file LICENSE URL https://github.com/ropensci/mapr BugReports https://github.com/ropensci/mapr/issues LazyData true LazyLoad true VignetteBuilder knitr Imports ggplot2, leaflet, spocc (>= 0.6.0), sp, rworldmap, RColorBrewer, jsonlite, gistr, data.table Suggests testthat, ggmap, knitr, taxize, maptools RoxygenNote 6.0.1 X-schema.org-applicationCategory Geospatial X-schema.org-keywords maps, mapping, ggplot, leaflet, interactive, biodiversity, occurrences X-schema.org-isPartOf https://ropensci.org NeedsCompilation no Author Scott Chamberlain [aut, cre] (<https://orcid.org/0000-0003-1444-9135>) Maintainer Scott Chamberlain <myrmecocystus@gmail.com> Repository CRAN Date/Publication 2018-03-21 17:27:27 UTC 1

2 mapr-package R topics documented: mapr-package........................................ 2 gbif_eg1........................................... 3 hull............................................. 3 map_ggmap......................................... 4 map_ggplot......................................... 6 map_gist........................................... 8 map_leaflet......................................... 10 map_plot.......................................... 12 occ2sp............................................ 14 occdat_eg1......................................... 15 style_geojson........................................ 15 Index 16 mapr-package Visualize species occurrence data Visualize species occurrence data Many inputs All functions take the following kinds of inputs: Package API Author(s) An object of class occdat, from the package spocc. An object of this class is composed of many objects of class occdatind An object of class occdatind, from the package spocc An object of class gbif, from the package rgbif An object of class data.frame. This data.frame can have any columns, but must include a column for taxonomic names (e.g., name), and for latitude and longitude (we guess your lat/long columns, starting with the default latitude and longitude) An object of class SpatialPoints An object of class SpatialPointsDatFrame map_plot() - static Base R plots map_ggplot() - static ggplot2 plots map_ggmap() - static ggplot2 plots with map layers map_leaflet() - interactive Leaflet.js interactive maps map_gist() - ineractive, shareable maps on GitHub Gists Scott Chamberlain <myrmecocystus@gmail.com>

gbif_eg1 3 gbif_eg1 Example dataset: output from call to rgbif::occ_search() A dataset with 50 rows, and 101 columns, from the query: rgbif::occ_search(scientificname = "Puma concolor", li Format A data frame with 50 rows and 101 variables hull Add a convex hull to a map Usage Add a convex hull to a map hull(x,...) Arguments x Details Value input... ignored Can be used with map_leaflet(), map_plot(), and map_ggplot(). Other methods in this package may be supported in the future. Adds a convex hull to the plot. See grdevices::chull() for info. Examples # map spocc output, here using a built in object data(occdat_eg1) map_plot(occdat_eg1, hull = TRUE) # map rgbif output, here using a built in object hull(map_ggplot(occdat_eg1)) ## Not run:

4 map_ggmap # leaflet spp <- c('danaus plexippus', 'Accipiter striatus', 'Pinus contorta') dat <- occ(spp, from = 'gbif', limit = 30, has_coords = TRUE) hull(map_leaflet(dat)) # ggplot library("rgbif") res <- occ_search(scientificname = "Puma concolor", limit = 100) hull(map_ggplot(res)) # base plots out <- occ(query='accipiter striatus', from='gbif', limit=25, has_coords=true) map_plot(out, hull = TRUE) ## End(Not run) map_ggmap ggpmap visualization of species occurences Usage ggpmap visualization of species occurences map_ggmap(x, zoom = 3, point_color = "#86161f", color = NULL, size = 3, lon = "longitude", lat = "latitude", maptype = "terrain", source = "google",...) Arguments x zoom point_color color The data. An object of class occdat, occdatind, gbif, gbif_data, SpatialPoints, SpatialPointsDataFrame, or data.frame. The package spocc needed for the first two, and rgbif needed for the third. When data.frame input, any number of columns allowed, but with at least the following: name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.) zoom level for map. Adjust depending on how your data look. Default color of your points. Deprecated, use color Default color of your points. size point size, Default: 3 lon, lat maptype (character) Longitude and latitude variable names. Ignored unless data.frame input to x parameter. We attempt to guess, but if nothing close, we stop. Default: longitude and latitude (character) map theme. see get_map in ggmap for options. Default: none

map_ggmap 5 Details Note source... Ignored (character) Google Maps ("google"), OpenStreetMap ("osm"), Stamen Maps ("stamen"), or CloudMade maps ("cloudmade"). Default: osm Does not support adding a convex hull via hull() BEWARE: this may error for you with a message like GeomRasterAnn was built with an incompatible version of ggproto. This is fixed in the dev version of ggmap, but not in the CRAN version. Apologies for the problem. Examples ## Not run: # BEWARE: this may error for you with a message like # "GeomRasterAnn was built with an incompatible version of ggproto". # This is fixed in the dev version of ggmap, but not in the CRAN # version. Apologies for the problem. ## spocc gd <- occ(query = 'Accipiter striatus', from = 'gbif', limit=75, has_coords = TRUE) map_ggmap(gd) map_ggmap(gd$gbif) ## rgbif library("rgbif") ### occ_search() output res <- occ_search(scientificname = "Puma concolor", limit = 100) map_ggmap(res) ### occ_data() output res <- occ_data(scientificname = "Puma concolor", limit = 100) map_ggmap(res) #### many taxa res <- occ_data(scientificname = c("puma concolor", "Quercus lobata"), limit = 30) map_ggmap(res) ## data.frame df <- data.frame(name = c('poa annua', 'Puma concolor', 'Foo bar'), longitude = c(-120, -121, -123), latitude = c(41, 42, 45), stringsasfactors = FALSE) map_ggmap(df) ### usage of occ2sp()

6 map_ggplot #### SpatialPointsDataFrame spdat <- occ2sp(gd) map_ggmap(spdat) # many species, each gets a different color spp <- c('danaus plexippus', 'Accipiter striatus', 'Pinus contorta') dat <- occ(spp, from = 'gbif', limit = 30, has_coords = TRUE, gbifopts = list(country = 'US')) map_ggmap(dat) map_ggmap(dat, zoom = 5) map_ggmap(dat, color = '#6B944D') map_ggmap(dat, color = c('#976aae', '#6B944D', '#BD5945')) ## End(Not run) map_ggplot ggplot2 mapping Usage ggplot2 mapping map_ggplot(x, map = "world", point_color = "#86161f", color = NULL, size = 3, lon = "longitude", lat = "latitude",...) Arguments x Value map point_color color The data. An object of class occdat, occdatind, gbif, gbif_data, SpatialPoints, SpatialPointsDataFrame, or data.frame. The package spocc needed for the first two, and rgbif needed for the third. When data.frame input, any number of columns allowed, but with at least the following: name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.) (character) One of world, world2, state, usa, county, france, italy, or nz Default color of your points. Deprecated, use color Default color of your points. size point size, Default: 3 lon, lat... Ignored A ggplot2 map, of class gg/ggplot (character) Longitude and latitude variable names. Ignored unless data.frame input to x parameter. We attempt to guess, but if nothing close, we stop. Default: longitude and latitude

map_ggplot 7 Examples # map spocc output, here using a built in object data(occdat_eg1) map_ggplot(occdat_eg1) # map rgbif output, here using a built in object data(gbif_eg1) map_ggplot(gbif_eg1) ## Not run: ## spocc ddat <- occ(query = 'Lynx rufus californicus', from = 'gbif', limit=100) map_ggplot(ddat) map_ggplot(ddat$gbif) map_ggplot(v, "usa") map_ggplot(ddat, "county") ### usage of occ2sp() #### SpatialPoints spdat <- occ2sp(ddat) map_ggplot(spdat) #### SpatialPointsDataFrame spdatdf <- as(spdat, "SpatialPointsDataFrame") map_ggplot(spdatdf) ## rgbif library("rgbif") library("ggplot2") ### occ_search() output res <- occ_search(scientificname = "Puma concolor", limit = 100) map_ggplot(res) ### occ_data() output res <- occ_data(scientificname = "Puma concolor", limit = 100) map_ggplot(res) #### many taxa res <- occ_data(scientificname = c("puma concolor", "Quercus lobata"), limit = 30) map_ggplot(res) ### add a convex hull map_ggplot(res) + hull() ## data.frame df <- data.frame(name = c('poa annua', 'Puma concolor', 'Foo bar'), longitude = c(-120, -121, -121), latitude = c(41, 42, 45), stringsasfactors = FALSE) map_ggplot(df)

8 map_gist # many species, each gets a different color spp <- c('danaus plexippus', 'Accipiter striatus', 'Pinus contorta') dat <- occ(spp, from = 'gbif', limit = 30, has_coords = TRUE) map_ggplot(dat, color = c('#976aae', '#6B944D', '#BD5945')) ## End(Not run) map_gist Make an interactive map to view in the browser as a GitHub gist Make an interactive map to view in the browser as a GitHub gist Usage map_gist(x, description = "", public = TRUE, browse = TRUE, lon = "longitude", lat = "latitude",...) Arguments x description public browse lon, lat The data. An object of class occdat, occdatind, gbif, gbif_data, SpatialPoints, SpatialPointsDataFrame, or data.frame. The package spocc needed for the first two, and rgbif needed for the third. When data.frame input, any number of columns allowed, but with at least the following: name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.) for the Github gist, or leave to default (=no description) (logical) Whether gist is public (default: TRUE) If TRUE (default) the map opens in your default browser. (character) Longitude and latitude variable names. Ignored unless data.frame input to x parameter. We attempt to guess, but if nothing close, we stop. Default: longitude and latitude... Further arguments passed on to style_geojson() Details See gistr::gist_auth() for help on authentication Does not support adding a convex hull via hull()

map_gist 9 Examples ## Not run: ## spocc spp <- c('danaus plexippus', 'Accipiter striatus', 'Pinus contorta') dat <- occ(spp, from=c('gbif','ecoengine'), limit=30, gbifopts=list(hascoordinate=true)) dat <- fixnames(dat, "query") # Define colors map_gist(dat, color=c('#976aae','#6b944d','#bd5945')) map_gist(dat$gbif, color=c('#976aae','#6b944d','#bd5945')) map_gist(dat$ecoengine, color=c('#976aae','#6b944d','#bd5945')) # Define colors and marker size map_gist(dat, color=c('#976aae','#6b944d','#bd5945'), size=c('small','medium','large')) # Define symbols map_gist(dat, symbol=c('park','zoo','garden')) ## rgbif library("rgbif") ### occ_search() output res <- occ_search(scientificname = "Puma concolor", limit = 100) map_gist(res) ### occ_data() output res <- occ_data(scientificname = "Puma concolor", limit = 100) map_gist(res) #### many taxa res <- occ_data(scientificname = c("puma concolor", "Quercus lobata"), limit = 30) res map_gist(res) ## data.frame df <- data.frame(name = c('poa annua', 'Puma concolor', 'Foo bar'), longitude = c(-120, -121, -121), latitude = c(41, 42, 45), stringsasfactors = FALSE) map_gist(df) ### usage of occ2sp() #### SpatialPoints spdat <- occ2sp(dat) map_gist(spdat) #### SpatialPointsDataFrame spdatdf <- as(spdat, "SpatialPointsDataFrame") map_gist(spdatdf)

10 map_leaflet ## End(Not run) map_leaflet Make interactive maps with Leaflet.js Usage Make interactive maps with Leaflet.js map_leaflet(x, lon = "longitude", lat = "latitude", color = NULL, size = 13,...) Arguments x Details Value lon, lat color The data. An object of class occdat, occdatind, gbif, gbif_data, SpatialPoints, SpatialPointsDataFrame, or data.frame. The package spocc needed for the first two, and rgbif needed for the third. When data.frame input, any number of columns allowed, but with at least the following: name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.) (character) Longitude and latitude variable names. Ignored unless data.frame input to x parameter. We attempt to guess, but if nothing close, we stop. Default: longitude and latitude Default color of your points. size point size, Default: 13... Ignored We add popups by default, and add all columns to the popup. The html is escaped with htmltools::htmlescape() a Leaflet map in Viewer in Rstudio, or in your default browser otherwise Examples ## Not run: ## spocc (out <- occ(query='accipiter striatus', from='gbif', limit=50, has_coords=true)) ### with class occdat map_leaflet(out) ### with class occdatind map_leaflet(out$gbif)

map_leaflet 11 ### use occ2sp map_leaflet(occ2sp(out)) ## rgbif library("rgbif") res <- occ_search(scientificname = "Puma concolor", limit = 100) map_leaflet(res) ## SpatialPoints class library("sp") df <- data.frame(longitude = c(-120,-121), latitude = c(41, 42), stringsasfactors = FALSE) x <- SpatialPoints(df) map_leaflet(x) ## SpatialPointsDataFrame class library("rgbif") ### occ_search() output res <- occ_search(scientificname = "Puma concolor", limit = 100) x <- res$data library("sp") x <- x[stats::complete.cases(x$decimallatitude, x$decimallongitude), ] coordinates(x) <- ~decimallongitude+decimallatitude map_leaflet(x) ### occ_data() output res <- occ_data(scientificname = "Puma concolor", limit = 100) map_leaflet(res) #### many taxa res <- occ_data(scientificname = c("puma concolor", "Quercus lobata"), limit = 30) res map_leaflet(res) ## data.frame df <- data.frame(name = c('poa annua', 'Puma concolor'), longitude = c(-120,-121), latitude = c(41, 42), stringsasfactors = FALSE) map_leaflet(df) # many species spp <- c('danaus plexippus', 'Accipiter striatus', 'Pinus contorta') dat <- occ(spp, from = 'gbif', limit = 50, has_coords = TRUE) map_leaflet(dat) map_leaflet(dat, color = c('#afff71', '#AFFF71', '#AFFF71')) map_leaflet(dat, color = c('#976aae', '#6B944D', '#BD5945')) # add a convex hull ## map_leaflet(dat) %>% hull() # using pipes hull(map_leaflet(dat))

12 map_plot ## End(Not run) map_plot Base R mapping Usage Base R mapping map_plot(x, lon = "longitude", lat = "latitude", color = NULL, size = 1, pch = 16, hull = FALSE,...) Arguments x Value lon, lat color The data. An object of class occdat, occdatind, gbif, gbif_data, SpatialPoints, SpatialPointsDataFrame, or data.frame. The package spocc needed for the first two, and rgbif needed for the third. When data.frame input, any number of columns allowed, but with at least the following: name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.) (character) Longitude and latitude variable names. Ignored unless data.frame input to x parameter. We attempt to guess, but if nothing close, we stop. Default: longitude and latitude Default color of your points. size point size, Default: 1 pch point symbol shape, Default: 16 hull (logical) whether to add a convex hull. Default: FALSE... Further args to graphics::points() Plots a world scale map Examples # map spocc output, here using a built in object data(occdat_eg1) map_plot(occdat_eg1) # map rgbif output, here using a built in object data(gbif_eg1) map_plot(gbif_eg1) ## Not run: ## spocc

map_plot 13 (out <- occ(query='accipiter striatus', from='gbif', limit=25, has_coords=true)) ### class occdat map_plot(out) map_plot(out, hull = TRUE) ### class occdatind map_plot(out$gbif) map_plot(out$gbif, hull = TRUE) ## rgbif library("rgbif") ### occ_search() output res <- occ_search(scientificname = "Puma concolor", limit = 100) map_plot(res) map_plot(res, hull = TRUE) ### occ_data() output res <- occ_data(scientificname = "Puma concolor", limit = 100) map_plot(res) #### many taxa res <- occ_data(scientificname = c("puma concolor", "Quercus lobata"), limit = 30) res map_plot(res) ## data.frame df <- data.frame( name = c('poa annua', 'Puma concolor', 'Foo bar', 'Stuff things'), longitude = c(-125, -123, -121, -110), latitude = c(41, 42, 45, 30), stringsasfactors = FALSE) map_plot(df) map_plot(df, hull = TRUE) ### usage of occ2sp() #### SpatialPoints spdat <- occ2sp(out) map_plot(spdat) map_plot(spdat, hull = TRUE) #### SpatialPointsDataFrame spdatdf <- as(spdat, "SpatialPointsDataFrame") map_plot(spdatdf) map_plot(spdatdf, hull = TRUE) # many species, each gets a different color spp <- c('danaus plexippus', 'Accipiter striatus', 'Pinus contorta', 'Ursus americanus') dat <- occ(spp, from = 'gbif', limit = 30, has_coords = TRUE, gbifopts = list(country = 'US')) map_plot(dat)

14 occ2sp map_plot(dat, hull = TRUE) ## diff. color for each taxon map_plot(dat, color = c('#976aae', '#6B944D', '#BD5945', 'red')) map_plot(dat, color = c('#976aae', '#6B944D', '#BD5945', 'red'), hull = TRUE) # add a convex hull library("rgbif") res <- occ_search(scientificname = "Puma concolor", limit = 100) map_plot(res, hull = FALSE) map_plot(res, hull = TRUE) ## End(Not run) occ2sp Create a spatial points dataframe from a spocc search Usage Create a spatial points dataframe from a spocc search occ2sp(x, coord_string = "+proj=longlat +datum=wgs84", just_coords = FALSE) Arguments x Details The resuslts of a spocc search called by spocc::occ() coord_string A valid EPGS cooridate string from the sp package, the default is WSGS 84 just_coords Return data frame with specios names and provenance or just a spatial points object, which is the default. This function will return either a spatial points dataframe or spatial points object. Conversion to spatial points objects allows spocc searches to interact with other spatial data sources. More coordinate system codes can be found at the EPGS registry: http://www.epsg-registry.org/ Examples ## Not run: ### See points on a map library("maptools") data(wrld_simpl) plot(wrld_simpl[wrld_simpl$name == "United States", ], xlim = c(-70, -60)) out <- occ(query = "Accipiter striatus", from = c("vertnet", "gbif"), limit = 50) xx <- occ2sp(out, just_coords = TRUE) points(xx, col = 2)

occdat_eg1 15 ## End(Not run) occdat_eg1 Example dataset: output from call to spocc::occ() A dataset with 25 rows, and 62 columns, from the query: spocc::occ(query='accipiter striatus', from='gbif', lim Format A data frame with 25 rows and 62 variables style_geojson Style a data.frame prior to converting to geojson. Usage Style a data.frame prior to converting to geojson. style_geojson(input, var = NULL, var_col = NULL, var_sym = NULL, var_size = NULL, color = NULL, symbol = NULL, size = NULL) Arguments input var var_col var_sym var_size color symbol size A data.frame A single variable to map colors, symbols, and/or sizes to. The variable to map colors to. The variable to map symbols to. The variable to map size to. Valid RGB hex color An icon ID from the Maki project http://www.mapbox.com/maki/ or a single alphanumeric character (a-z or 0-9). One of small, medium, or large

Index Topic datasets gbif_eg1, 3 occdat_eg1, 15 Topic package mapr-package, 2 gbif_eg1, 3 gistr::gist_auth(), 8 graphics::points(), 12 grdevices::chull(), 3 htmltools::htmlescape(), 10 hull, 3 hull(), 5, 8 map_ggmap, 4 map_ggmap(), 2 map_ggplot, 6 map_ggplot(), 2, 3 map_gist, 8 map_gist(), 2 map_leaflet, 10 map_leaflet(), 2, 3 map_plot, 12 map_plot(), 2, 3 mapr (mapr-package), 2 mapr-package, 2 occ2sp, 14 occdat_eg1, 15 rgbif::occ_search(), 3 spocc::occ(), 14, 15 style_geojson, 15 style_geojson(), 8 16