Closed
Description
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
Labels
No labels