par_mf | R Documentation |
par
's mfrow
or mfcol
arguments to fit n
plots on a single pageFor a given number of plots, this function defines a vector of two values for the mfrow
(or mfcol
) arguments of par
such that all plots can fit on a single page. This is particularly useful if you are producing plots for multiple groups (e.g. individuals), each of which contains a varying number of subplots: in this scenario, you do not have to manually specify mfrow
or mfcol
for each plot; you can simply pass the number of plots to plot_mf()
, inside par
, to define a suitable, case-specific layout.
par_mf(n)
n |
An integer which defines the number of plots to be produced on a single page. |
The function returns a vector comprising two integers, which can be passed to the mfrow
(or mfcol
) arguments of par
to plot n
plots on a single page.
Edward Lavender
This function was inspired by the implementation of the pages
argument in plot.gam
.
#### Example (1): Implement par_mf() for n plots
par_mf(10)
par_mf(20)
par_mf(23)
#### Example (2): Use par_mf() to define par()'s mfrow argument:
pp <- par(mfrow = par_mf(3))
plot(1, 2); plot(2, 4); plot(8, 9)
par(pp)
#### Example (3): Use par_mf() to define par()'s mfcol argument in the same way:
pp <- par(mfcol = par_mf(3))
plot(1, 2); plot(2, 4); plot(8, 9)
par(pp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.