leaflet icon indicating copy to clipboard operation
leaflet copied to clipboard

addLegend: colors and labels arguments do not add NA into the legend

Open davidhodge931 opened this issue 3 years ago • 0 comments

Using pal and values arguments adds NA to legend.

library(leaflet)

df <- local({
  n <- 300; x <- rnorm(n); y <- rnorm(n)
  z <- sqrt(x ^ 2 + y ^ 2); z[sample(n, 10)] <- NA
  data.frame(x, y, z)
})

pal <- colorBin("OrRd", df$z)

leaflet(df) %>%
  addTiles() %>%
  addCircleMarkers(~x, ~y, color = ~pal(z)) %>%
  addLegend(pal = pal, values = ~z) 

image

But using colors and labels arguments does not adds NA to legend

colors <- RColorBrewer::brewer.pal(6, "OrRd")
labels <- LETTERS[1:6]

leaflet(df) %>%
  addTiles() %>%
  addCircleMarkers(~x, ~y, color = ~pal(z)) %>%
  addLegend(colors = colors, labels = labels)

image

davidhodge931 avatar Nov 04 '21 20:11 davidhodge931