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?
To draw multiple curves in one plot, different functions are created separately and the curve() function is called repeatedly for each curve function. The call for every other curve() function except for the first one should have added an attribute set to TRUE so that multiple curves can be added to the same plot.
R par() function R programming has a lot of graphical parameters which control the way our graphs are displayed. The par() function helps us in setting or inquiring about these parameters. For example, you can look at all the parameters and their value by calling the function without any argument.
The mfrow() parameter allows to split the screen in several panels. Subsequent charts will be drawn in panels. You have to provide a vector of length 2 to mfrow() : number of rows and number of columns.
The grid-based graphics functions in lattice and ggplot2 create a graph object, but do not display it. The print()
method for the graph object produces the actual display, i.e.,
print(qplot(x, y))
solves the problem.
See R FAQ 7.22.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With