4

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.

smci
  • 32,567
  • 20
  • 113
  • 146
Frank P.
  • 503
  • 5
  • 21

2 Answers2

10

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.

Jthorpe
  • 9,756
  • 2
  • 49
  • 64
  • 5
    The last sentence is *super important*. The best way to do it is to save the old par, and re-set it automatically using `on.exit`: `oldpar = par(ask = TRUE); on.exit(par(oldpar))`. – Konrad Rudolph Jan 31 '15 at 22:20
1

A simpler solution for this that I've found is what plot.lm() does somewhere in the beginning of the function:

oask <- devAskNewPage(TRUE);
on.exit(devAskNewPage(oask));