我一辈子都想不通为什么我不能刷牙来为下面的两个地块(p1,p2)工作。
我所期待的:如果我单击左侧条形图中的特定钻石切割,则相应的切割应在散点图中突出显示。
下面的可重现示例
library(crosstalk);library(tidyverse);library(plotly)
d = ggplot2::diamonds %>% slice_sample(prop = 0.01)
m <- d %>% highlight_key(~cut)
#m = crosstalk::SharedData$new(d, key = ~cut)
p1 = m$data() %>% count(cut) %>% plot_ly() %>% add_bars(x = ~cut, y = ~n, color =~cut)
p2 = m %>% plot_ly() %>% add_markers(x = ~carat, y = ~price, color = ~cut)
subplot(p1,p2) %>% highlight('plotly_click') %>% hide_legend()
但是,如果两个图都是非聚合图,这确实有效。
library(crosstalk);library(tidyverse);library(plotly)
d = ggplot2::diamonds %>% slice_sample(prop = 0.01)
m <- d %>% highlight_key(~cut)
#m = crosstalk::SharedData$new(d, key = ~cut)
p1 = m %>% plot_ly() %>% add_markers(x = ~color, y = ~price, color = ~cut)
p2 = m %>% plot_ly() %>% add_markers(x = ~carat, y = ~price, color = ~cut)
subplot(p1,p2) %>% highlight('plotly_click') %>% hide_legend()