3

plot.lm has a nice feature of displaying plots one after another, so when specifying

plot(lm(rnorm(100) ~ rnorm(100, 3, 1)))

displays first plot and asks user to

Hit Return to see next plot:

Now I want to generate 30 plots, so displaying them in a grid will make them hard to read, while specifying them one after another is quite cumbersome. I've been wondering if there is a function or a method to imitate plot.lm behaviour? I'm specifically interested in a function that is compatible with ggplot2.

1
  • Also note that in most graphics devices you can navigate between plots. Commented Jul 17, 2018 at 10:55

1 Answer 1

7
+50

Study stats:::plot.lm. It uses devAskNewPage.

Example:

devAskNewPage(TRUE)
for (i in 1:3) plot(i)
devAskNewPage(options("device.ask.default")[[1]])
Sign up to request clarification or add additional context in comments.

6 Comments

Or par(ask = TRUE)
devAskNewPage(options("device.ask.default")) doesn't seem to work fine (Error in devAskNewPage(options("device.ask.default")) : incorrect argument 'ask'). Is it safe to use something like devAskNewPage(FALSE)? Also, should it work ok with ggplot2?
Thanks. Do you know any alternative that works with ggplot2?
@jakes ; what is wrong with this answer as it seems to extend to ggplot okay; change the relevant bit of Roland's code to for (i in 1:3) print(qplot(main=i))
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.