R Plotly默认取消选择跟踪

时间:2016-09-21 20:21:53

标签: r plotly

我正在使用R Plotly并且有一行表格:

add_trace(y = meanRank,
          x = DateOnly,
          data = timeSeriesDF,
          name = "Daily Value",
          text = hoverText,
          hoverinfo = "text",
          showlegend = TRUE)

工作正常。但是,当显示绘图时,我希望此轨迹“未选中”。因此,用户可以在图例上单击它以显示该行。我似乎找不到要显示的参数。

2 个答案:

答案 0 :(得分:17)

您可以添加visible = "legendonly"

library(plotly)
economics %>%
 transform(rate = unemploy / pop) %>%
 plot_ly(x = date, y = rate) %>%
 loess(rate ~ as.numeric(date), data = .) %>%
 broom::augment() %>%
 add_trace(y = .fitted, name = "foo", visible = "legendonly")

enter image description here

请参阅reference

答案 1 :(得分:2)

您可以使用属性' visible = legendonly'到其他add_函数,例如:

add_lines(x = as.Date(x()$ds),
          y = round(y()$total),
          name = 'Inventory Total',
          visible = 'legendonly')