I took me a long time to understand how to use a loop into a plotly plot. The trick is to use the evaluate=TRUE option. Watch out! I don’t know why but apparently, you need to re-make the layout at each loop. Don’t forget that most of the time you can use the option color = my_groups to draw several traces. (See graph #121). Does’nt work anymore with the new version of plotly… Sorry for the inconvenienve. Please tell me if you have a solution…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# plotly library library(plotly) # Create data my_y=rnorm(10)*3 my_x=seq(0,9) # Let's do a first plot p<-plot_ly(y=my_y, x=my_x , type="scatter", mode="markers+lines") # Add 5 trace to this graphic with a loop! for(i in 1:3){ my_y=rnorm(10) p<-add_trace(p, y=~my_y, x=~my_x , type="scatter", mode="markers+lines" ) #p=layout(yaxis=list(range=c(-10,9))) } p |
Not what you are looking for ? Make a new search ![mediatagger]
Leave a Reply