首页 > 解决方案 > 编辑传单 labelFormat 的源代码以编辑中断/刻度线

问题描述

我正在尝试编辑leaflet图例。有谁知道使用预定义调色板时如何编辑数量breaks和放置位置 ?这是我得到的图例(下面的代码)是:tick-markscolorNumericcolorQuantilelabelFormat

在此处输入图像描述

如您所见,这是一个高度倾斜的图例,如果休息点位于c(1, 3, 6, 9)或类似的东西可以很容易地编辑,包括限制,它会更有意义。

您可以包括bins,但根据帮助文件,这些将是等距的:

在此处输入图像描述

从这个链接看来你可以做到这一点,colorQuantile但这不是我想要的。我想我可能需要像这个例子一样浏览源代码,但我看不到我可以在哪里编辑breaks或打勾。

我的另一个问题之后的可重现代码:

#following my other question:
#https://stackoverflow.com/questions/60321495/merging-palettes-with-colorramppalette-and-plotting-with-leaflet/
library(leaflet)
library(tidyverse)

set.seed(8)
df <- data.frame(var = rnorm(100)^2)
df <- df %>% 
  arrange(var) %>% 
  mutate(ranking = 1:n()) 
threshold <- sum(df$var < 1)   
 # number of values below threshold 
threshold #= 67

### Create an asymmetric color range
## Make vector of colors for values smaller than 1 
rc1 <- colorRampPalette(colors = c("#006837", "#1A9850"), space = "Lab")(threshold)    

## Make vector of colors for values larger than 1
rc2 <- colorRampPalette(colors = c("#FDAE61", "#A50026"), space = "Lab")(length(df$var) - threshold)

## Combine the two color palettes
rampcols <- c(rc1, rc2)

# Create a palette for a legend with ranking again. But this time with
# colorNumeric()

mypal2 <- colorNumeric(palette = rampcols, domain = df$ranking)

leaflet() %>% 
  addLegend(pal = mypal2, values = df$ranking,
            #bins = 10,
            labFormat = labelFormat(transform = function(x) df$var[x]))

有人有什么建议吗?谢谢

标签: rcolorsformattingleafletlegend

解决方案


推荐阅读