For 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)

Arguments

n

An integer which defines the number of plots to be produced on a single page.

Source

This function was inspired by the implementation of the pages argument in plot.gam.

Value

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.

Author

Edward Lavender

Examples

#### Example (1): Implement par_mf() for n plots par_mf(10)
#> [1] 3 4
par_mf(20)
#> [1] 4 5
par_mf(23)
#> [1] 5 5
#### 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)