Legendgroup with different trace types in plotly chart

I am trying to create a chart with a bar trace and a scatter trace. I want to control the legend thru the same group but it doesnt work

graph_hist <- plot_ly(source="histPlot") %>%
       add_trace(y=g$Pct, x=g$lot_wafer, color=g$name, type="bar", key=g$name, legendgroup=g$name, showlegend=F) %>%
       add_trace(y=g$Pct, x=g$lot_wafer, color=g$name , type="scatter", key=g$lot_wafer,legendgroup=g$name, showlegend=T, opacity=1) %>%
        layout(dragmode="select", barmode="stack")

Any help? Main reason for doing the 2 traces is because plotly_selected is not supported for bar chart :frowning:

Thanks

Hey @punnu35,

In what way or manner do you mean?

Both traces work with one legend in this example:

pct <- c(2,3,4,2)
lot_wafer <- c("a","b","c","d")
name <- c("aa","bb","cc","dd")

plot_ly() %>%
  add_trace(y=pct, x=lot_wafer, color=name, type="bar", key=name, legendgroup=name, showlegend=T) %>%
  add_trace(y=pct, x=lot_wafer, color=name, type="scatter", key=lot_wafer, legendgroup=name, showlegend=F, opacity=1) %>%
  layout(dragmode="select", barmode="stack")