gpt4 book ai didi

r - R : How to customize the coloring of clusters?的传单

转载 作者:行者123 更新时间:2023-12-04 07:19:52 25 4
gpt4 key购买 nike

如何在R的传单包中自定义addMarkers函数的颜色?

群集的默认颜色是:

  • 1-10绿色
  • 11-100黄色
  • 100+红色

  • 我想将范围和颜色更改为:
  • 1-100红色
  • 101-1000黄色
  • 1000+绿色

  • JS Leaflet具有以下功能:
    https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

    是否可以通过R包中的markerClusterOptions参数来实现?
    leaflet(quakes) %>% addTiles() %>% addMarkers(
    clusterOptions = markerClusterOptions()
    )

    最佳答案

    您可以使用iconCreateFunction中的markerClusterOptions创建自己的自定义图标功能来显示聚类标记。

    在您的示例中,您可能只需要修改默认标记功能(找到here),然后修改if/else循环来设置标记的CSS类即可。可以为标记着色的默认CSS可以找到here。如果您想进行更多定制,则可以创建自己的类。

    这是一个代码示例(大号是红色,中号是黄色,小号是绿色,所以我只是切换了默认代码以匹配您的条件):

    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) });

    }"))
    )

    关于r - R : How to customize the coloring of clusters?的传单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33600021/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com