Skip to content
Prev 25392 / 29559 Next

Colors for factors in leaflet r

I think you want this:

pal <- colorFactor(palette = c("red", "blue", "green"), levels =
levels(meuse$soil))
leaflet(meuse) %>%
  addTiles() %>%
  addCircleMarkers(stroke = FALSE, fillOpacity = 1, color = ~pal(soil)) %>%
  addLegend("topright", pal, values=~soil, labels=c("Type 1", "Type 2",
"Type 3"), title="Soil type")

Kent