auto_layout | R Documentation |
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
auto_layout(n, layout = T)
n |
the number of plots |
layout |
should the function return a preallocated layout object? If |
either a matrix or a layout object
Dustin Fife
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.