R Plotly 默认取消选择跟踪Plotly

2023-09-06 07:23:43 作者:女人每天早上打开衣柜挑衣服就好像皇帝选妃,选着选着就觉得自己

我正在使用 R Plotly 并有一行如下形式:

I am ussing R Plotly and have a line of the form:

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

它工作正常.但是,我希望在显示绘图时取消选择"此跟踪.因此,用户将在图例上单击它以显示该行.我似乎找不到显示的参数.

It works fine. However, I want this trace to be "unselected" when the plot is shown. So a user would click it on the legend to show the line. I can't seem to find the parameter to show that.

推荐答案

你可以添加 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")

参见参考.