user3786999
user3786999

Reputation: 1127

How can I hide a trace in a legend in R plotly

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?

Upvotes: 12

Views: 12086

Answers (1)

Gautam
Gautam

Reputation: 2753

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

Upvotes: 18

Related Questions