我有一个 R 脚本,用于制作带有传单地图的闪亮应用程序。该地图包括基于四分位数计算的图例。图例显示了每个四分位数的范围,但我想显示“第一四分位数”、“第二四分位数”等。我尝试在“AddLegend”下添加“标签”,但没有使用。你知不知道怎么?您可以从下面的 GitHub 链接查看脚本和相关文件。太感谢了。
https://github.com/e5t2o/exploring_shiny/blob/master/InteractiveMap/app.R
小智 6
我一直在寻找解决方案,并在此评论中找到了一个解决方案: 在传单中手动添加图例值
这是一种解决方法,但由于某种原因它有效。你可以写:
# Define palette
pal <- colorBin(UNICEF, domain = oo$Value, bins = bins, na.color = "#F1F1F1")
# Define labels
labels <- c("1st Quartile", "2nd Quartile", "3rd Quartile", "4th Quartile")
output$mymap <- renderLeaflet({
leaflet(data = oo) %>%
addPolygons( # Fill in your parameters
) %>%
addLegend( # Legend options
pal = pal, # Previously defined palette
values = ~Value, # Values from data frame
opacity = 0.7, # Opacity of legend
title = NULL, # Title
position = "bottomleft",
labFormat = function(type, cuts, p) { # Here's the trick
paste0(labels)
}
) %>%
setView( # Fill in your map boundaries
)
Run Code Online (Sandbox Code Playgroud)