在传单中手动添加图例值 [英] Manually adding legend values in leaflet

查看:82
本文介绍了在传单中手动添加图例值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Leaflet绘制各种英国大选的结果,并遇到传说中的问题.

I'm plotting results from various British elections in Leaflet and ran into a bit of a problem with legends.

对于大选中的各种结果,我对不同的数据(图片中的黄色->紫色比例)使用具有不同域的相同颜色函数

For the various results in the general election I'm using the same colour function with different domain for the different data (the yellow-> purple scale in the picture)

这是通过以下方式创建的(以前两个为例):

This is created with (for the first two as examples):

labvotescols <- colorNumeric(
  c("Yellow", "Purple"),
  domain = Westminster$LabourVotes,
  ukipvotescols <- colorNumeric(
    c("Yellow", "Purple"),
    domain = Westminster$UKIPVotes,

以此类推...

目前我有传说

map = map %>% addLegend("bottomright", pal = ukipvotescols, values = Westminster$UKIPVotes,
                    title = "(e.g.) % voting UKIP at GE2015",
                    opacity = 1)

作为此示例,但实际上,我想摆脱图例上的所有值,仅在黄色端保留较少",在紫色端保留更多".这可能吗?

as one example of this, but really I'd like to get rid of all the values on the legend and just have "less" at the yellow end and "more" at the purple end. Is this possible?

我尝试玩耍,然后谷歌搜索,但无济于事.

I tried playing around and then googling but to no avail.

推荐答案

您可以将其从黄色->紫色刻度更改为自己的刻度:

You could change it from a yellow->purple scale and make your own scale:

map = map %>% addLegend("bottomright", 
  colors =c("#FFC125",  "#FFC125", "#8A4117", "#7D0552", "#571B7E"),
  labels= c("less", "","","","", "more"),
  title= "(e.g.) % voting UKIP at GE2015"
  opacity = 1)

如果获得正确的颜色,则外观应该相似.不是您要找的答案,但这是一个不错的解决方法.您的输出将如下所示:

If you get the correct colors then it should look similar. Not the answer you were looking for, but it's a good workaround. Your output would look like this:

花更多的时间寻找更好的颜色过渡,您会得到一个图例,看起来与顶部的黄紫色调色板相似.

Spend more time looking for better color transition and you could get a legend that looks similar to the yellow-purple color pallet you have up top.

这篇关于在传单中手动添加图例值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆