custom breaks in addLegend leaflet

I am struggling to add custom breaks to addLegend in leaflet. I want the values to range from -1 to 1, with breaks at every 0.5. I’ve tried the bins argument, but it is not accepting my numeric vector correctly (It either doesn’t include the first and last number in label or is completely wrong) How can I do this?


pal2 <- colorNumeric("YlOrRd", domain = dataset$variable)

dataset %>% leaflet() %>%
  addProviderTiles("CartoDB.PositronNoLabels") %>%
  addPolygons(weight = 0.25, stroke = TRUE, color = "black", fillColor = ~pal2(dataset$variable), label = ~paste0("SCORE: ", variable)) %>%
  addLegendNumeric(position = "bottomright", pal = pal2, values = ~variable, title = "text<sub>text</sub>")

Leave a Comment