Plot map of species occurrences (or any set of point coordinates) on top of different background layers.
occmap(
locs,
ras = NULL,
bg = "Esri.WorldImagery",
type = c("base", "ggplot", "leaflet"),
pcol = "red",
alpha = 1,
psize = 1,
add = FALSE,
prev.map = NULL,
...
)
An sf::sf()
or terra::SpatVector()
object with point coordinates,
e.g. as generated from locs2sf()
or locs2vect()
.
A terra::SpatRaster()
object to be used as background for points.
If NULL (default), a background map defined by bg
will be used.
Character. Type of background map to be used if ras
is not provided.
bg
should be one of the providers listed in maptiles::get_tiles()
if
type
is 'base' or 'ggplot', or one of the providers listed in
leaflet::addProviderTiles()
if type
is 'leaflet'.
Character. One of "base", "ggplot" or "leaflet" to define the type of map produced.
Colour to be used for points. Default is "red".
Colour transparency for points, between 0 (fully transparent) and 1 (fully opaque).
Point size. Default is 1 (cex = 1).
Logical. Add locs
coordinates to a previous 'base' map? (e.g. for a new species).
Map to be used as basemap to add further points (only applicable for "leaflet" and "ggplot" map types).
additional parameters to be passed to
terra::plot()
if type = "base"
tidyterra::geom_spatraster()
if type = "ggplot"
or leaflet::addCircleMarkers()
if type = "leaflet"
.
A map plus a leaflet or ggplot object, depending on type
.
if (FALSE) { # interactive()
## Example coordinates
locs <- data.frame(lon = c(-5.8, -5.5, -5.9), lat = c(35.7, 36.2, 36.5))
locs <- locs2sf(locs, crs = 4326)
## Default map
occmap(locs, psize = 6)
occmap(locs, psize = 6, bg = "CartoDB.Positron") # Change background
## Interactive (leaflet) map
occmap(locs, psize = 6, type = "leaflet")
occmap(locs, psize = 6, type = "leaflet", bg = "CartoDB.Positron")
## ggplot map
occmap(locs, psize = 6, type = "ggplot")
## Adding points to a previous map
new.locs <- data.frame(lon = c(-5.8, -5.4), lat = c(36.2, 36.5))
new.locs.sf <- locs2sf(new.locs, crs = 4326)
## base
map <- occmap(locs, psize = 6)
occmap(new.locs.sf, add = TRUE, psize = 6, pcol = "blue")
## Adding points to a previous map (leaflet)
map <- occmap(locs, psize = 6, type = "leaflet")
occmap(new.locs.sf, prev.map = map, psize = 6, pcol = "blue")
## Adding points to a previous map (ggplot)
map <- occmap(locs, psize = 6, type = "ggplot")
occmap(new.locs.sf, prev.map = map, psize = 6, pcol = "blue")
}