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
I'd do this like this:
mean <- -0.0007200342
sd <- 0.3403711
N=10
T=1
Delta = T/N
# a list with the trace Y values
Ws <- lapply(
1:15,
function(idx){
c(0,cumsum( sqrt(Delta) * rnorm(N, mean=mean, sd=sd)))
}
)
# this could be a list with the trace X values, but is just a seq
t <- seq(0,T, length=N+1)
# a list with plotly compliant formatted objects
formattedW <- lapply(
seq_along(Ws),
function(idx, datasetY, datasetX){
return(list( x = datasetX, y = datasetY[[idx]], type="scatter", mode = 'lines+markers'))
},
datasetX = t,
datasetY = Ws
)
# Reduce the list of plotly compliant objs, starting with the plot_ly() value and adding the `add_trace` at the following iterations
Reduce(
function(acc, curr){
do.call(add_trace,c(list(p=acc),curr))
},
formattedW,
init=plot_ly()
)