r - 编辑传单 labelFormat 的源代码以编辑中断/刻度线
问题描述
我正在尝试编辑leaflet
图例。有谁知道在使用预定义调色板时如何编辑数量breaks
和放置位置 ?这是我得到的图例(下面的代码)是:tick-marks
colorNumeric
colorQuantile
labelFormat
如您所见,这是一个高度倾斜的图例,如果休息点位于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]))
有人有什么建议吗?谢谢
解决方案
推荐阅读
- swift - Firestore 响应“在范围内找不到‘卡片’”
- r - 未找到 Eval 对象“MEDV”中的线性回归错误
- sequence - 为什么在实践中不使用斐波那契数列的封闭形式?
- java - 从两个视图中获取相同的对象
- python - Python OpenCV 错误:(-215:断言失败)_step >= minstep in function 'cv::Mat::Mat'
- arrays - 最简单的准系统循环将整数添加到循环中使用 .space 制作的数组中,然后检索它们并按 MIPS 组装的顺序打印它们
- python - shutil 说子文件夹正在使用中,因此无法移动它并且程序崩溃但一切都已成功移动
- github - 通过 RESTful SDK 解决项目卡中的 GitHub 问题
- python - Python web scraper 不适用于深度嵌套的标签
- javascript - 发送消息,包括按钮