R传单地图-根据所选图层组更改图例 [英] R leaflet map - Change legends based on selected layer group

查看:78
本文介绍了R传单地图-根据所选图层组更改图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作R传单地图(不是Shiny),我有两个对照组,根据选择,我希望看到一个不同的图例.目前,我只能设法同时看到两个图例.

I am making an R leaflet map (not Shiny) and I have two control groups, and based on the selection I would like a different legend to become visible. Currently I only manage to have both legends visible at all time.

下面是传单地图的代码,可以在图像中看到输出.

Below is the code for the leaflet map, and the output can be seen in the image.

leaflet() %>% addSearchOSM() %>% 
  addProviderTiles(providers$CartoDB.Positron,
                   options = providerTileOptions(noWrap = TRUE),
                   group = "kaart") %>%
  # addFullscreenControl() %>%
  addCircleMarkers(data = table@data,
             lat = ~lng, 
             lng = ~lat,
             color = ~palverbruikplaats(Verbruiksplaats),
             label = bepaalPopup(),
             group = "Verbruikplaatscircles"
             )%>%
  addCircleMarkers(data = table@data,
                   lat = ~lng, 
                   lng = ~lat,
                   color = ~palstatus(`Status omschrijving`),
                   label = bepaalPopup(),
                   group = "statuscircles"
                    )%>%
  leaflet::addLegend("bottomleft", pal = palverbruikplaats, values = verbruikplaatsuniek, title = "Legenda") %>%
  leaflet::addLegend("bottomleft", pal = palstatus, values = statusuniek, title = "Legenda") %>%
  addLayersControl(baseGroups = c("Verbruikplaatscircles", "statuscircles"),
                      options = layersControlOptions(collapsed = FALSE))

推荐答案

在您的addLayersControl中,您是要设置overlayGroups自变量而不是baseGroups吗?

In your addLayersControl did you mean to set the overlayGroups argument instead of baseGroups?

library(leaflet)
leaflet() %>%
  addTiles(group = "OpenStreetMap") %>%
  addCircleMarkers(runif(20, -75, -74), runif(20, 41, 42), group = "Markers1", color ="red") %>%
  addMarkers(runif(20, -75, -74), runif(20, 41, 42), group = "Markers2") %>%
  addLegend(values = 1, group = "Markers1", position = "bottomleft", labels = "1", colors= "red") %>%
  addLegend(values = 2, group = "Markers2", position = "bottomleft", labels = "2" ,colors= "blue") %>%  
  addLayersControl(overlayGroups = c("Markers1", "Markers2"),
                   options = layersControlOptions(collapsed = FALSE))

这篇关于R传单地图-根据所选图层组更改图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆