Building plotly graph in for loop not displaying all series

后端 未结 1 553
萌比男神i
萌比男神i 2021-01-18 11:48

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 &         


        
1条回答
  •  无人共我
    2021-01-18 12:15

    The reason beats me but you are asking for 'any way to get around this'.

    Instead of passing the whole data.table at once, you could specify the required y-values in the loop and it should work.

    df <- data.table(matrix(1:9,ncol = 3))
    exPlot <- plot_ly(df[[1]])
    theCols <- c("V2","V3")
    for(i in 1:2){
      exPlot <- add_lines(exPlot,
                          y = df[[theCols[i]]],
                          type = "scatter",
                          mode = "lines")
    }
    exPlot
    

    0 讨论(0)
提交回复
热议问题