0

If I run the code below, I am not able to see the plots change as the for-loop gets executed very quickly.

for(i in 1:10) {
    plot(rnorm(20))
}

I am wondering if there is a way to slow down the for-loop and create one plot every 5 seconds. Thanks!

Maxime Rouiller
  • 13,453
  • 9
  • 55
  • 106
Filly
  • 683
  • 11
  • 22
  • 1
    Rather than pausing, you can save the figures you produce using `pdf(...); plot(...); dev.off()` sequence, where you generate the name of the file by doing something like `t_plot_name – rbatt Dec 08 '15 at 17:27

1 Answers1

1

You can wait for user input before showing the next plot:

# Wait for user input before showing next plot
par(ask=TRUE) 

# Loop that makes plots
for(i in 1:10) {
  plot(rnorm(20))
}

To actually wait for 5 seconds between plots:

# Loop that makes plots
for(i in 1:10) {
  plot(rnorm(20))
  # Wait 5 seconds
  Sys.sleep(5)
}
ialm
  • 8,222
  • 3
  • 35
  • 48