问题
I have a conundrum...
I created a function that will plot 11 plots arranged as 4x3 (i.e., mfrow=c(4,3)
) plots per device window. However, I want the function to do this multiple times with different inputs, thus generating multiple pages of 11 graphs each. The issue is that since I have one "empty" slot per page (12 - 11 = 1), I have to tell the code to start each iteration of plotting on a new window. I've done so by explicitly adding the windows()
function directly into the function. This works just fine.
The problem now, though, is if/when I want to save the output of this function as a .pdf file. Even though I wrap the function within the pdf()
device code,
pdf('savegraphics.pdf', width = 8, height = 10.5, paper = 'letter')
func(...)
dev.off()
the graphics are still opened in graphics windows in R (and never get saved to the .pdf file). I'm fairly certain that the issue causing this is the fact that I call windows()
in the original function.
So my question is:
Is there a way to "skip" to a new graphics window when creating multiple windows/pages of graphics that will also work when creating pages in a pdf?
回答1:
You could do something similar to
layout(matrix(1:4)) # or par(mfrow = c(4, 1))
plot(1:10)
plot(1:10)
plot(1:10)
plot.new()
where for your 12th plot you insert plot.new()
.
来源:https://stackoverflow.com/questions/41510522/how-to-start-new-graphics-window-and-or-graphics-page-in-r