R Plotly Deselect trace by default


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.





Please read how to provide minimal reproducible examples in R. 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 Answers
2



You could add visible = "legendonly":


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.





exactly what I needed.
– user1357015
Sep 21 '16 at 20:29



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


add_


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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined

Opening a url is failing in Swift