Coloring clusters inside leaflet

I am trying to change the default colors from green, yellow orange to Dark Red, light red and Gray(or something like that)

Here is what I have so far

clrs <- colorRampPalette(c("red","green", "blue"))(3)
crime_clean_2021 %>% filter(crime=="THEFT")%>%
  leaflet() %>% 
     addProviderTiles(providers$Esri.WorldGrayCanvas, group = "Grey") %>%
    addAwesomeMarkers(lng = ~long, lat = ~lat, color = clrs) 

I wrote a post about tuning leaflet markers that you may find interesting: Leaflet Map Markers in R ยท Jindra Lacko

Anyway: you have to take care with {leaflet} and colors; you are dealing not with R colors (where you can use colorRampPalette) but with HTML colors.

Your code is not readily reproducible, but you will likely want to convert your clrs variable to a factor and map the colors via a leaflet::colorFactor() call; take care that your colors follow HTML naming convention (red, green and blue are OK) and be mindful of the tilde convention in referencing data frame columns from within a leaflet call.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.