Flyer for R: How to adjust cluster color?

How to customize the coloring of the addMarkers function in the flyer package for R?

By default for clusters:

  • 1-10 Green
  • 11-100 Yellow
  • 100+ Red

I would like to change the ranges and colors to something like:

  • 1-100 Red
  • 101-1000 Yellow
  • 1000+ Green

JS Leaflet has this feature: https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

Is this possible through the markerClusterOptions parameter in package R?

leaflet(quakes) %>% addTiles() %>% addMarkers(
  clusterOptions = markerClusterOptions()
)
+4
source share
1 answer

You can use iconCreateFunctionin markerClusterOptionsto create your own icon function to display cluster markers.

( ) if/else, CSS . CSS , , . , .

( , - , - , , ):

library(leaflet)
leaflet(quakes) %>% addTiles() %>% addMarkers(
  clusterOptions = markerClusterOptions(iconCreateFunction=JS("function (cluster) {    
    var childCount = cluster.getChildCount(); 
    var c = ' marker-cluster-';  
    if (childCount < 100) {  
      c += 'large';  
    } else if (childCount < 1000) {  
      c += 'medium';  
    } else { 
      c += 'small';  
    }    
    return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });

  }"))
)
+6

Source: https://habr.com/ru/post/1614965/


All Articles