addRasterLegend | R Documentation |
A function for adding a legend that is specifically designed for terra::SpatRaster objects, with categorical values, that carry their own color table.
addRasterLegend(map, x, layer = 1, ...)
map |
a map widget object |
x |
a SpatRaster object with a color table |
layer |
the layer of the raster to target |
... |
additional arguments to pass through to |
addRasterImage()
library(terra)
r <- rast("/vsicurl/https://geodata.ucdavis.edu/test/pr_nlcd.tif")
leaflet() %>%
addTiles() %>%
addRasterImage(r, opacity = 0.75) %>%
addRasterLegend(r, opacity = 0.75)
plot.new() # pause in interactive mode
rr <- r
levels(rr) <- NULL
leaflet() %>%
addTiles() %>%
addRasterImage(rr, opacity = 0.75) %>%
addRasterLegend(rr, opacity = 0.75)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.