0

我正在处理链接 Leaflet 和 d3scatter 图的多变量数据。它适用于一个变量。如果我尝试通过第二个 addCircleMarkers 和 addLayersControl 在 Leaflet 中包含第二个变量,那么 sharedData 链接会中断,过滤不起作用并且刷牙不起作用。提前致谢。附上 MWE:

library("crosstalk")
library("d3scatter")
library("leaflet")

Long <- c(117.4,117.5,117.6)
Lat<- c(-33.7,-33.8,-33.9)
var1 <- c(21,22,23)
var2 <- c(31,32,33)
species <- c(8,9,10)

df1<- data.frame(Long, Lat, var1, var2, species)
sdf1 <- SharedData$new(df1)

col_1 <- c( "yellow" ,"black" ,"orange")
col_2 <- c("red" ,"green" ,"blue")


l <- leaflet(sdf1)%>% 
  setView(117.5, -33.8, 10) %>% 
  addCircleMarkers(radius = 1, color = col_1, group = "1") %>%
#  addCircleMarkers(radius = 1, color =  col_2, group = "2") %>%
# PROBLEM  -  adding the second "addCircleMarkers" enables the overlayGroups but 
#             it breaks the link between the plots and breaks the filter
  addLayersControl(overlayGroups=c("1","2"))


m <- list(l, filter_checkbox("unique_id_for_species", "Animal Species", sdf1, ~species))
n <- list(d3scatter(sdf1, ~var2, ~var1, color = ~species, x_lim = c(30,40), y_lim = c(20,25), width="70%",  height=200),
          d3scatter(sdf1, ~var1, ~var2, color = ~species, y_lim = c(30,40), x_lim = c(20,25), width="70%",  height=200))

bscols(m, n)
4

0 回答 0