我试图让我的传单地图在选择两个图层时都没有显示图例,并且只选择了一个图层时显示该图层的图例。
我使用Javascript找到了这些解决方案:
但是我无法弄清楚如何在R中应用这些技术。任何人都可以指出我要阅读的文档,或者可以给我一个提示吗?
以下是一些测试数据:
df1
Tickets long lat
1 28 -71.12088 42.37418
2 4 -71.09524 42.36911
3 3 -71.11935 42.38532
df2
Tickets long lat
4 33 -71.1213 42.37401
5 1 -71.0915 42.37255
6 21 -71.1226 42.37512
7 1 -71.1016 42.36411
以下是一段代码:
base_map <- leaflet() %>%
addProviderTiles('Stamen.TonerLite') %>%
setView(-71.128184, 42.3769824, zoom = 14)
pal1 <- colorNumeric(palette = "RdBu",
domain = df1$Tickets)
pal2 <- colorNumeric(palette = "RdBu",
domain = df2$Tickets)
base_map %>%
addCircles(data = df1, lng = df1$long, lat = df1$lat,
color = pal1(df1$Tickets), radius = 5, group = "Group 1 Dots") %>%
addLegend("bottomright", pal = pal1, values = df1$Tickets,
title = "1 Dots") %>%
addCircles(data = df2, lng = df2$long, lat = df2$lat,
color = pal2(df2$Tickets), radius = 5, group = "Group 2 Dots") %>%
addLegend("bottomright", pal = pal2, values = df2$Tickets,
title = "2 Dots") %>%
addLayersControl(overlayGroups = c("Group 1 Dots", "Group 2 Dots"),
options = layersControlOptions(collapsed = FALSE))
感谢。