如何在 R 中的图例中隐藏痕迹

use*_*999 3 r plotly

我有一个带有几条痕迹的情节图。其中一些我不想出现在传说中。我该怎么做呢?

Gau*_*tam 5

您需要showlegend = F在跟踪中设置:

代码

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')
  )
Run Code Online (Sandbox Code Playgroud)

输出

在此处输入图片说明