If you want to get a number of plots in the same window or figure, the *arrangePlots* function can help you find the adequate number of rows and columns in which to arrange them. This can be especially useful inside a function that can generate plots whose number you don’t initially know — it is used e.g. in the *optiThresh* function. Both these functions are included in the modEvA package (Barbosa et al. 2014).

arrangePlots <- function(n.plots, landscape = FALSE) {
# version 1.0 (16 Sep 2013)
root <- sqrt(n.plots)
large <- ceiling(root)
small <- round(root)
if (landscape) plots.rc <- c(small, large)
else plots.rc <- c(large, small)
return(plots.rc)
} # end arrangePlots function

[presented with Pretty R]

Usage examples (e.g. for 6 plots):

par(mfrow = arrangePlots(6))

for(i in 1:6) plot(i)

par(mfrow = arrangePlots(6, landscape = TRUE))

for(i in 1:6) plot(i)

**REFERENCES:**

Barbosa A.M., Brown J.A. & Real R. (2014) modEvA â€“ an R package for model evaluation and analysis. R package, version 0.1.

### Like this:

Like Loading...

*Related*