Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

r - Plotly: add_trace in a loop

I'm trying to add_trace ad each loop, but I get only one plot with multiplies lines on over each other.

mean <- -0.0007200342
sd   <- 0.3403711
N=10
T=1
Delta = T/N

W = c(0,cumsum( sqrt(Delta) * rnorm(N, mean=mean, sd=sd)))
t <- seq(0,T, length=N+1)

p<-plot_ly(y=W, x=t)

for(i in 1:5){

  W <- c(0,cumsum( sqrt(Delta) * rnorm(N, mean=mean, sd=sd)))
  p<-add_trace(p, y=W)

}
print(p)

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The plot_ly and add_trace functions have an evaluation = FALSE option that you can change to TRUE, which should fix the scope issues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...