Search code examples
rplotpromptinteractivesequential

How to write an R function that displays plots sequentially?


I want something similar to the 'plot.lm' functionality.

y <- rnorm(100, 0, 1)
x <- rnorm(100, 0, 1.5)

mod <- lm(y ~ x)

plot(mod)

Hit <Return> to see next plot: 
Hit <Return> to see next plot: 
Hit <Return> to see next plot: 
Hit <Return> to see next plot:

I want to create several plots and then display them sequentially - prompting the user to hit in order to see all the plots.


Solution

  • Just set par(ask=TRUE) before calling plot(). You might want to set it after your first plot, so the user doesn't have to wait for that one. To be nice, set par(ask=FALSE) after your last plot.