【问题标题】:Manually adding legend values in leaflet在传单中手动添加图例值
【发布时间】:2016-07-02 14:10:59
【问题描述】:

我在 Leaflet 中绘制了各种英国选举的结果,但在传说中遇到了一点问题。

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

这是用(以前两个为例)创建的:

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)

作为一个例子,但我真的想去掉图例上的所有值,只在黄色端有“少”,在紫色端有“更多”。这可能吗?

我试着到处玩,然后用谷歌搜索,但无济于事。

【问题讨论】:

  • 我有一种感觉,考虑到中断/标签等是由addLegend 计算的渐变,它不会让你在其中放置字符串。
  • 我给出了类似的答案 herehere 。也许你可以从这些解决方案中总结出一些东西。

标签: r leaflet legend palette


【解决方案1】:

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

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

如果你得到正确的颜色,那么它应该看起来相似。不是您正在寻找的答案,但这是一个很好的解决方法。您的输出将如下所示:

花更多的时间寻找更好的颜色过渡,您可以获得一个看起来类似于您顶部的黄紫色调色板的图例。

【讨论】:

  • mypal &lt;- colorNumeric(c("Yellow", "Purple"), domain = df$values, na.color = "Black") 用于调色板,map = map %&gt;% addLegend("bottomright", pal = mypal, values = df$values, title = "quant data title", opacity = 1, labFormat = function(type, cuts, p) { n = length(cuts) cuts[n] = "more" for (i in 2:(n-1)){cuts[i] = ""} cuts[1] = "less" paste0(cuts[-n], cuts[-1])}) 用于图例,对我有用。我会把它留在这里以防有人来看。我确信它有一些问题,但到目前为止它一直在坚持。
  • @John Friel,很好的答案,OP 应该接受并关闭这个问题。
猜你喜欢
  • 2014-11-20
  • 1970-01-01
  • 2017-07-22
  • 1970-01-01
  • 1970-01-01
  • 2014-02-13
  • 1970-01-01
  • 2020-06-27
  • 1970-01-01
相关资源
最近更新 更多