mfrow.Rd
mfrow
and mfcol
setup a multi-figure layout scheme on a
grid in the current graphics device. Unlike other layout methods the
schemes can be used recursively to create complex layouts with very
simple commands.
either a numeric vector of length one defining the number of equally spaced rows or a vector specifying the relative height of each row.
either a numeric vector of length one defining the number of equally spaced columns or a vector specifying the relative width of each row.
if rows
and cols
are both not specified, then
n
specifies the minimal number of cells that the layout
should contain. In that case rows
and cols
are
computed such that their product is at least n
and the
resulting aspect ratio of the figures is as close to asp
as
possible.
numeric, desired aspect ratio of the figures when n
is used to specify the grid
logical, if TRUE
then the layout scheme is added to
the layout stack, allowing recursive layouts. Otherwise the
currently layout is replaced with the new grid layout.
number of times this layout should be applied or
NA
for unlimited. Any number larger than 1e6 is interpreted
as NA
.
boundaries of the figure that will be split using this layout scheme.
additional arguments that will be passed to
par
when a new figure is setup.
mfrow
and mfcol
have a similar effect as the
corresponding graphics parameters, but they are more flexible
(allowing individual withs and heights) and construct a scheme that
can be used recursively with add = TRUE
.
Note that the scheme layout method is incompatible with all other
layout methods that are not based on the scheme stack, such as
par(mfrow)
or layout
. It can be to a degree
combined with split.screen
with add = TRUE
if
used as a sub-layout thereof since screen
uses a co-operative
manipulation of figures. However, in that case you should make sure
that the stack layout does not overflow (i.e., you plot only at most
as many plots as there are figures) or it will clear the device.
object of the class scheme
.
All layout functions require R 2.13.0 or higher! If plots seemingly don't move from the first figure then you either have old version or other code has removed the neessary "before.plot.new" hook.
## one advantage is that you can simply specify the number of plots
## the layout will then depend on the aspect ratio of the device
mfrow(n=8)
par(mar=c(2,2,0,0))
for (i in 1:8) plot(rnorm(100), rnorm(100), col=i, pch=19)
## or you can create recursive layouts
mfrow(2, 4) ## 4 x 2 base grid
mfrow(c(1, 4), 1, add=TRUE) ## each cell split asymetrically 1:4
par(mar=rep(0,4))
for (i in 1:8) {
plot(0:1, 0:1, type='n', axes=FALSE); rect(0,0,1,1); text(0.5, 0.5, i)
plot(rnorm(100), rnorm(100), col=i, pch=19, axes=FALSE)
}