add multiple lines to a plot_ly graph with add_trace

旧巷老猫 提交于 2019-12-05 02:49:21

You need to set evaluate = TRUE to force evalutation / avoid lazy evaluation

p <- plot_ly()
p
for(line in my_lines) {  p <- add_trace(p, y=line[['y']], x=line[['x']], 
                 marker=list(color=line[['color']]),
                 evaluate = TRUE)
}
p

I believe with the release of plotly 4.0 calling any of the add_* family of functions forces evaluation so there is no need to call evaluate = T anymore

So, something like this should work fine:

devtools::install_github("ropensci/plotly")
library(plotly)

p <- plot_ly()

for(i in 1:5){
  p <- add_trace(p, x = 1:10, y = rnorm(10), mode = "lines")
}

p

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!