Skip to contents

Add a color legend for a heatmap

Usage

addHeatmapLegend(
  map,
  values,
  colors = NULL,
  max = NULL,
  title = "Intensity",
  position = "bottomright",
  layerId = NULL,
  opacity = 1,
  ...
)

Arguments

map

a map widget object created from leaflet()

values

numeric intensity values. The legend goes from 0 to max, matching how Leaflet.heat colors intensity / max.

colors

a color palette name, a vector of colors, a colorNumeric function, or a WebGL gradientTexture name such as "skyline" or "OrRd". The default matches the Leaflet.heat blue-cyan-lime-yellow-red ramp.

max

upper end of the legend. Defaults to the maximum of values.

title

legend title

position

the position of the legend

layerId

the ID of the legend; subsequent calls to addLegend or addControl with the same layerId will replace this legend. The ID can also be used with removeControl.

opacity

legend opacity

...

additional arguments passed to addLegend

Examples

leaflet(quakes) %>%
  addProviderTiles(providers$CartoDB.DarkMatter) %>%
  addHeatmap(lng = ~long, lat = ~lat, intensity = ~mag) %>%
  addHeatmapLegend(values = quakes$mag, title = "Magnitude")