Skip to content

Clicking on a group in the legend does not hide all traces associated to that legendgroup #1148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zcesur opened this issue Nov 10, 2017 · 0 comments

Comments

@zcesur
Copy link

zcesur commented Nov 10, 2017

I am trying to associate 2 different traces with the same legend so that when I click on a particular group in the legend, both traces for that group becomes hidden. I was able to achieve this using the toy dataset df1 given below, but if I scale it up and create a bigger dataset df2, the feature no longer works.

library(plotly)
set.seed(42)

df1 <- data.frame(x = 1:5,
                  y = runif(5),
                  group = letters[1:5])

plot_ly(data = df1, x = ~x) %>%
  add_trace(y=~y, color=~group, type="bar", legendgroup=~group, showlegend=T) %>%
  add_trace(y=~y, color=~group, type="scatter", legendgroup=~group, showlegend=F)

df2 <- data.frame(x = 1:100,
                  y = runif(100),
                  group = rep(letters[1:5]), 20)

plot_ly(data = df2, x = ~x) %>%
  add_trace(y=~y, color=~group, type="bar", legendgroup=~group, showlegend=T) %>%
  add_trace(y=~y, color=~group, type="scatter", legendgroup=~group, showlegend=F)

P.S. Apologies for not being able to share a reprex. It throws an error the reason for which I could not quite figure out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant