I have a data frame like c = (lat, lng, decile)
which decile has ten levels. obviously, by ggmap and ggplot we can plot some points in given (lat,lng) as if we set color
argument to decile column in geom_point
it will classify the points and add legend automatically. But, I used leaflet to shoe the map. using this
I have written this code:
pal <- colorNumeric(
palette = colorRampPalette(rainbow(10))(length(c$decile)),
domain = c$decile)
c %>% leaflet() %>% addTiles() %>% addCircleMarkers(color = ~ pal(deciles))
and I have points on my map in ten colors. so, my question has two parts:
-is there a simple way like ggplot to classify colors in the leaflet?
-how can I add a legend for these ten colors? in addLegend(labels , colors)
how should I fix the arguments?
UPDATE:
this is my c
> head(c)
lat lon decile
1 35.68705 51.38176 4
2 35.80742 51.48610 6
3 35.69151 51.39816 5
4 35.66665 51.35095 2
5 35.77566 51.40209 7
6 35.70326 51.41348 8