Skip to content

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

Closed
@zcesur

Description

@zcesur

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions