plet {terra} | R Documentation |
Plot the values of a SpatRaster or SpatVector to make an interactive leaflet map that is displayed in a browser.
These methods require that packageVersion("leaflet") > "2.1.1"
or the development version of leaflet that you can install with remotes::install_github("rstudio/leaflet")
.
## S4 method for signature 'SpatRaster'
plet(x, y=1, col, alpha=0.8, main=names(x), tiles=NULL,
wrap=TRUE, maxcell=500000, legend="bottomright",
shared=FALSE, panel=FALSE, collapse=TRUE, map=NULL)
## S4 method for signature 'SpatVector'
plet(x, y="", col, alpha=1, fill=0, main=y, cex=1, lwd=2, popup=TRUE,
label=FALSE, split=FALSE, tiles=c("Streets", "Esri.WorldImagery", "OpenTopoMap"),
wrap=TRUE, legend="bottomright", collapse=FALSE, map=NULL)
## S4 method for signature 'SpatVectorCollection'
plet(x, col, alpha=1, fill=0, cex=1, lwd=2, popup=TRUE,
label=FALSE, tiles=c("Streets", "Esri.WorldImagery", "OpenTopoMap"), wrap=TRUE,
legend="bottomright", collapse=FALSE, map=NULL)
## S4 method for signature 'leaflet'
lines(x, y, col, lwd=2, alpha=1)
## S4 method for signature 'leaflet'
points(x, y, col, cex=1, alpha=1, popup=FALSE)
x |
SpatRaster, SpatVector, or leaflet object |
y |
missing, or positive integer, or character (variable or layer name) indicating the layer(s) to be plotted. If |
col |
character. Vector of colors or color generating function |
alpha |
Number between 0 and 1 to set the transparency for lines (0 is transparent, 1 is opaque) |
fill |
Number between 0 and 1 to set the transparency for polygon areas (0 is transparent, 1 is opaque) |
tiles |
character or NULL. Names of background tile providers |
wrap |
logical. if |
maxcell |
positive integer. Maximum number of cells to use for the plot |
legend |
character to indicate the legend position ("bottomleft", "bottomright", "topleft" or "topright") or NULL to suppress the legend |
main |
character. Title for the legend. The length should be 1 if |
shared |
logical. Should the legend be the same for all rasters (if multiple layers of SpatRaster |
map |
leaflet object |
collapse |
logical. Should the layers "control" panel be collapsed? |
split |
logical. IF |
cex |
numeric. point size magnifier. See |
lwd |
numeric, line-width. See |
popup |
logical. Should pop-ups be created? |
label |
logical. Should mouse-over labels be added? |
panel |
logical. Should SpatRaster layers be shown as a panel" |
## Not run:
if (require(leaflet)) {
if (packageVersion("leaflet") > "2.1.1") {
v <- vect(system.file("ex/lux.shp", package="terra"))
p <- spatSample(as.polygons(v, ext=T), 10)
values(p) = data.frame(id=11:20, name=letters[1:10])
m <- plet(v, "NAME_1", alpha=.5, tiles="")
m <- points(m, p, col="gray", cex=2, popup=T)
lines(m, v)
plet(v, "NAME_1", split=TRUE, alpha=.2) |>
points(p, col="gray", cex=2, popup=T) |> lines(v)
s <- svc(v, p)
names(s) <- c("the polys", "set of points")
plet(s, col=c("red", "blue"), lwd=1)
r <- rast(system.file("ex/elev.tif", package="terra"))
plet(r, main="Hi\nthere") |> lines(v, lwd=1)
plet(r, tiles="Streets") |> lines(v, lwd=2, col="blue")
x <- c(r, 50*classify(r, 5))
names(x) <- c("first", "second")
# each their own legend
plet(x, 1:2, tiles="Streets", collapse=FALSE) |> lines(v, lwd=2, col="blue")
# shared legend
plet(x, 1:2, tiles="Streets", shared=TRUE, collapse=FALSE) |> lines(v, lwd=2, col="blue")
}}
## End(Not run)