Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Plotly Deselect trace by default

Tags:

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.

like image 660
user1357015 Avatar asked Sep 21 '16 20:09

user1357015


2 Answers

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.

like image 185
lukeA Avatar answered Nov 20 '22 11:11

lukeA


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')
like image 44
Jitboo Avatar answered Nov 20 '22 11:11

Jitboo