auto_layout: Automatically select the layout.

auto_layoutR Documentation

Automatically select the layout.

Description

Determine the arrangement of multiple plots in a single panel Given a particular number of plots, auto_layout will automatically determine the arrangement of each plot using the layout function or par(mfrow=c(nrow, ncol)). See examples. modified from: https://github.com/cran/fifer/blob/master/R/auto.layout.R

Usage

auto_layout(n, layout = T)

Arguments

n

the number of plots

layout

should the function return a preallocated layout object? If FALSE, it returns a matrix

Value

either a matrix or a layout object

Author(s)

Dustin Fife

Examples

## Not run: 
## plot six plots
auto_layout(6)
for (i in 1:6){
	plot(rnorm(100), rnorm(100))
}
## same as mar(mfrow=c(3,2))
par(mfrow=c(3,2))
for (i in 1:6){
	plot(rnorm(100), rnorm(100))
}
## default for odd number of plots using mfrow looks terrible
par(mfrow=c(3,2))
for (i in 1:5){
	plot(rnorm(100), rnorm(100))
}
## much better with auto_layout
auto_layout(5)
for (i in 1:5){
	plot(rnorm(100), rnorm(100))
}
## see matrices of layouts for multiple plots
##
for(i in 2:6){
  m <- auto_layout(i, layout=F)
  par(mfrow=c(nrow(m), ncol(m)))
  for (j in 1:i){
    plot(rnorm(100), rnorm(100))
  }
  Sys.sleep(1)
}

## End(Not run)

HemingNM/ENMwizard documentation built on Jan. 4, 2024, 3:24 p.m.