Arrange plots within a window

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)
}  # 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)


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



Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s