9

I have a plotly graph with several traces. Some of them I don't want to appear in the legend. How do I do this?

user3786999
  • 1,037
  • 3
  • 13
  • 24

1 Answers1

14

You need to set showlegend = F in your trace:

CODE

library(plotly)
plt <- plot_ly(as.data.frame(mtcars)) %>% 
  add_markers(x = ~wt, y = ~mpg, name = 'Fuel Eff.', type = 'scatter') %>% 
  add_markers(x = ~wt, y = ~hp, name = 'Power to wt. ratio', type = 'scatter', 
              showlegend = F) %>%
  layout(
    showlegend = T, 
    legend = list(orientation = 'h')
  )

Output

enter image description here

Gautam
  • 2,597
  • 1
  • 28
  • 51