R手册:如何自定义群集的颜色?

编程入门 行业动态 更新时间:2024-10-09 11:29:19
本文介绍了R手册:如何自定义群集的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何为R定制传单包中addMarkers函数的颜色?

How do I customize the coloring of the addMarkers function in the leaflet package for R?

群集的默认颜色是:

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

我想将范围和颜色更改为:

I'd like to change the ranges and colors to something like:

  • 1-100红色
  • 101-1000黄色
  • 1000+绿色

JS Leaflet具有以下功能: github/Leaflet/Leaflet.markercluster#customising-the集群标记

JS Leaflet has this capability: github/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

是否可以通过R包中的markerClusterOptions参数来实现?

Is this possible through a markerClusterOptions parameter in the R package?

leaflet(quakes) %>% addTiles() %>% addMarkers( clusterOptions = markerClusterOptions() )

推荐答案

您可以使用markerClusterOptions中的iconCreateFunction创建自己的自定义图标功能来显示群集标记.

You can use the iconCreateFunction in the markerClusterOptions to create your own custom icon function to display the cluster markers.

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

In your example, you can maybe just modify the default marker function (found here) and just modify the if/else loops setting the CSS class of the markers. The default CSS that colors the markers can be found here. You can create your own classes if you want more customisation.

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

Here's a code example (large is red coloring, medium is yellow, and small is green so I just switched the default code around to match your conditions):

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手册:如何自定义群集的颜色?

本文发布于:2023-07-19 13:46:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157103.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   颜色   手册

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!