leaflet
leaflet copied to clipboard
addLegend: colors and labels arguments do not add NA into the legend
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)
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)