map_leaflet | R Documentation |
Make interactive maps with Leaflet.js
map_leaflet( x, lon = "longitude", lat = "latitude", color = NULL, size = 13, name = NULL, ... )
x |
The data. An object of class |
lon, lat |
(character) Longitude and latitude variable names. Ignored
unless |
color |
Default color of your points. |
size |
point size, Default: 13 |
name |
(character) the column name that contains the name to use in
creating the map. If left |
... |
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
## Not run: ## spocc library("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) ### use occ2sp map_leaflet(occ2sp(out)) ## rgbif if (requireNamespace("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 if (requireNamespace("rgbif")) { 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 library("spocc") 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)) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.