I can't get brushing / linking to work with crosstalk and plotly for a 2 subplots when 1 subplot is an aggregate graph

465 Views Asked by At

I can't for the life of me figure out why I can't get brushing to work for my two plots (p1,p2) below.

What I'm expecting: If I click the a specific diamond 'cut in the bar graph on the left, the corresponding cut should be highlighted in the scatterplot.

brushing / linking NOT working

Reproducible example below

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()

This DOES, however, work if both graphs are NON-aggregate graphs.

working

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()
0

There are 0 best solutions below