简体   繁体   中英

R Plotly Deselect trace by default

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.

You could add 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")

在此输入图像描述

See the reference .

you can use the attribute 'visible = legendonly' to other add_ functions such as:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM