addRasterLegend: Add a color legend for a SpatRaster to a map

View source: R/layers.R

addRasterLegendR Documentation

Add a color legend for a SpatRaster to a map

Description

A function for adding a legend that is specifically designed for terra::SpatRaster objects, with categorical values, that carry their own color table.

Usage

addRasterLegend(map, x, layer = 1, ...)

Arguments

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 addLegend()

See Also

addRasterImage()

Examples



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)


leaflet documentation built on May 29, 2024, 1:19 a.m.