Generate multiple graphics from within an R function

Posted by William Doane on Stack Overflow See other posts from Stack Overflow or by William Doane
Published on 2010-03-30T17:40:06Z Indexed on 2010/03/30 17:43 UTC
Read the original article Hit count: 312

Filed under:
|

I'd like to spawn several graphics windows from within a function in R using ggplot graphics...

testf <- function(a, b) {
  devAskNewPage(TRUE)
  qplot(a, b);
  # grid.newpage(recording = TRUE)
  dev.new()
  qplot(a, a+a);
  # grid.newpage(recording = TRUE)
  dev.new()
  qplot(b, b+b);
}

library(ggplot2)

x <- rnorm(50)
y <- rnorm(50)
testf(x, y)

However, neither dev.new() nor grid.newpage() seems to flush the preceding plot.

I know that, in R, functions normally only produce the last thing they evaluate, but I'd like to understand the process better and to learn of any possible workarounds.

Thoughts?

© Stack Overflow or respective owner

Related posts about r

    Related posts about ggplot2