14

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.

Nils
  • 2,665
  • 15
  • 30
user1357015
  • 11,168
  • 22
  • 66
  • 111
  • 1
    Please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). You may want to edit & improve your question (and future ones) accordingly. A good R-related post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able in a new/clean R session. – lukeA Sep 21 '16 at 20:29

2 Answers2

30

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")

enter image description here

See the reference.

lukeA
  • 53,097
  • 5
  • 97
  • 100
7

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')
Nils
  • 2,665
  • 15
  • 30
Jitboo
  • 75
  • 1
  • 6