I am trying to create a plot in plot_ly in R that has many lines. I would like to be able to use the selection tool as well. An example is below:
library(plotly)
trace_0 <- rnorm(100, mean = 0)
trace_1 <- rnorm(100, mean = 0)
trace_2 <- rnorm(100, mean = 0)
x <- c(1:100)
data <- data.frame(x, trace_0, trace_1, trace_2)
plot_ly(data, x = ~x, y = ~trace_0, name = 'trace 0', type = 'scatter', mode = 'lines') %>%
add_trace(y = ~trace_1, name = 'trace 1', mode = 'lines') %>%
add_trace(y = ~trace_2, name = 'trace 2', mode = 'lines')
Based on this example, I have two questions in terms of tailoring it to my goal:
1) In the example above, the dimensions of the data was 100 rows and 4 columns. Let's say I had a data frame that was 100 rows and 50 columns. Is there a better method to add each of the new lines (by add_trace), or would I need to do that in a for-loop for 49 lines?
2) Is there a way I could still obtain the "select" option. Sometimes, when using plot_ly, there is a box and lasso selection tool that appears. However, for some reason, I am unable to get that by default with this plot at hand.
If you have any suggestions toward either of these goals, I would greatly appreciate your input! Thank you.