auto.mfrow: Space-efficient dimenions for figure panels

Description Usage Arguments Details See Also Examples

View source: R/auto.mfrow.R

Description

When generating multipanel figures, automatically determines arguments to par(mfrow=c(x,y)) that use space most efficiently, finding the balance between minimizing empty panels and achieving square panel dimensions.

Usage

1
auto.mfrow(x, tall = FALSE)

Arguments

x

numeric, the number of panels

tall

logical, if FALSE (the default), non-square panel arrangements will have more columns than rows (e.g., mfrow=c(2,3)).

Details

auto.mfrow will often produce figures with "empty" panels - auto.mfrow does not (necessarily) find dimenions suitable for publication, as for prime numbers this would often lead to 1-by-X or X-by-1 dimensions that would run off the screen/ page when x was large, which auto.mfrow avoids by permitting ampty panels. The ideal balance between non-square panel dimenions and empty panels is subjective, but the dimensions are found by the values of nr and nc that minimize the following expression: abs(sqrt(x)-(nr)) + abs(sqrt(x)-(nc)) + abs(nr*nc-x), with output switching between nr-by-nc and nc-by-nr depending on the value of tall).

See Also

See rbLib-package for package overview.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
N <- 5
par(mfrow=auto.mfrow(N))
for(i in 1:N){plot(1:i)}

# Example also showing number of panels given number of plots
panels <- c()
empty <- c()
for(i in 1:25){
	panels[i] <- prod(auto.mfrow(i))
	empty[i] <- panels[i] - i
}
par(mfrow=auto.mfrow(2, tall=TRUE), mar=c(2.5,2.5,0.25,0.25), mgp=c(1.15,0.25, 0), tcl=-0.15, ps=10)
plot(panels, xlab="Number of plots", ylab="number of panels")
abline(a=0,b=1)
plot(empty, xlab="Number of plots", ylab="number of empty panels", type="o")

rBatt/rbLib documentation built on May 26, 2019, 7:45 p.m.