【发布时间】:2017-04-05 16:49:02
【问题描述】:
通过一次添加一列来创建一个图就可以了
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
但是如果我尝试在 for 循环中做同样的事情,它只会显示第二个跟踪,覆盖第一个。
exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3)))
theCols <- c("V2","V3")
for(i in 1:2){
exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[i]), type = "scatter",mode = "lines")
}
exPlot
有什么办法可以解决这个问题?我环顾四周,设置“evaluate = TRUE”曾经是答案,但似乎已被弃用。
【问题讨论】:
-
与plotly的惰性评估有关,基于一些简单的谷歌搜索,曾经有一个参数评估= T,但它似乎已被弃用?