I can have an even or odd number of plots on each page, depending on the input data size/shape.
I set par(mfrow)
to values such that it is the smallest grid possible to hold all of the plots, but now I want to make sure it moves to the next page on the next loop iteration in the case where the total number of plots ends up odd or does not fit into a grid.
How can I force a new page? Google has shown me grid.newpage()
, but I get the error
> grid.newpage()
Error: could not find function "grid.newpage"
When I try to use it. Also, unless I am mistaken, base plotting does not use grid
anyways so that wouldn't help me.
Here's a suggested strategy: fill the empty cells with plot.new()
until the layout is filled; next plot will automatically push a new page.
n = 5
rc = n2mfrow(n)
par(mfrow=rc, mar=c(0,0,0,0))
for(ii in seq_len(n))
plot(rnorm(10))
for(ii in seq_len(prod(rc) - n))
plot.new()
plot(1,1) # on its own new page
Alternatively, you could try
while(!par('page')) plot.new()
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