Building plotly graph in for loop not displaying all series
问题 Creating a plot by adding one column at a time works just fine exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3))) theCols <- c("V2","V3") exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[1]), type = "scatter",mode = "lines") exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[2]), type = "scatter",mode = "lines") exPlot but if I try to do the same thing in a for loop, it only displays the second trace, overwriting the first one. exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3))