mfrow | R Documentation |
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.
mfrow(rows, cols, n, asp = 1, add = FALSE, times = NA, fig = if (add) par("fig") else c(0, 1, 0, 1), ...) mfcol(rows, cols, n, asp = 1, add = FALSE, times = NA, fig = if (add) par("fig") else c(0, 1, 0, 1), ...)
rows |
either a numeric vector of length one defining the number of equally spaced rows or a vector specifying the relative height of each row. |
cols |
either a numeric vector of length one defining the number of equally spaced columns or a vector specifying the relative width of each row. |
n |
if |
asp |
numeric, desired aspect ratio of the figures when |
add |
logical, if |
times |
number of times this layout should be applied or
|
fig |
boundaries of the figure that will be split using this layout scheme. |
... |
additional arguments that will be passed to
|
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.
Simon Urbanek
## 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) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.