如何在R Leaflet中自定义图例标签

5
我有一个R脚本,用于创建带有leaflet地图的闪亮应用程序。该地图包括基于四分位计算的图例。图例显示每个四分位的范围,但我想让它显示像“第一四分位数”,“第二四分位数”等。我尝试在“AddLegend”下添加“labels”,但没有用。您知道如何做吗?您可以从以下GitHub链接中查看脚本和相关文件。非常感谢。

https://github.com/e5t2o/exploring_shiny/blob/master/InteractiveMap/app.R

1个回答

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
                            )

3
类型、切割和P在哪里? - ethan tenison

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接