I have a dataframe named plt.total made of 5 rows (obs) and 7 columns (variables) as below:
set.seed(2018)
plt.total <- data.frame(replicate(7,runif(5, min=0.80, max=0.9)))
colnames(plt.total) <- c("R", paste0("Matrix",1:6))
plt.total[,1] <- c(1:5)
Then I plot it using plotly as below:
plot_ly(data=plt.total, x = ~R, y = ~Matrix1, name = 'Matrix 1', type = 'scatter', mode = 'lines',
line = list(color = 'rgb(205, 12, 24)', width = 3, dash = 'dashdot')) %>%
add_trace(y = ~Matrix2, name = 'Matrix 2', line = list(color = 'rgb(22, 96, 167)', width = 3, dash = 'solid' )) %>%
add_trace(y = ~Matrix3, name = 'Matrix 3', line = list(color = 'rgb(205, 12, 24)', width = 3, dash = 'longdashdot')) %>%
add_trace(y = ~Matrix4, name = 'Matrix 4', line = list(color = 'rgb(22, 96, 167)', width = 3, dash = 'dash')) %>%
add_trace(y = ~Matrix5, name = 'Matrix 5', line = list(color = 'rgb(205, 12, 24)', width = 3, dash = 'dot')) %>%
add_trace(y = ~Matrix6, name = 'Matrix 6', line = list(color = 'rgb(22, 96, 167)', width = 3, dash = 'dot')) %>%
layout(title = "", legend = list(x=0, y=0, font = list(family = "Times", size = 14, color = "#000")))
However, my problem is that the plt.total changes by the number of "columns" from time to time and I am trying to find a way to avoid modifying my scripts every time (using add_trace). Thus my goal is to plot the input each column of the dataframe using plotly regardless of the number of columns.
Thanks


