For a multi-plot square matrix (i.e., a multi-panel plot comprising a matrix of subplots for each combination of units, e.g., individuals), it can be useful to plot only the lower or upper triangle of the matrix to avoid visualisation of duplicate combinations. For a given square matrix, this function returns the indices of plots that lie along the lower or upper matrix.

par_tri(mf, type = "upper.tri")

Arguments

mf

A vector of two numbers that specify the number of subplots in each direction in a multi-panel plot (i.e., an input to par's mfrow or mfcol argument).

type

A character vector ("upper.tri" or "lower.tri") which specifies whether or not to return an index of subplots in the upper triangle or lower triangle. For plots filled by row, then column, this works as expected; for plots filled by column, then by row, "upper.tri" returns the lower triangle and "lower.tri" returns the upper triangle (see Examples).

Value

This function returns the indices of plots along the lower or upper triangle of a multi-panel figure.

Author

Edward Lavender

Examples

if (FALSE) { #### Example (1): Plot the upper triangle with par(mfrow = ...) pp <- par(mfrow = c(4, 4)) for(i in 1:16){ if(i %in% par_tri(mf = c(4, 4), type = "upper.tri")) plot(1) else plot.new() } par(pp) #### Example (2): Plot the lower triangle with par(mfrow = ...) pp <- par(mfrow = c(4, 4)) for(i in 1:16){ if(i %in% par_tri(mf = c(4, 4), type = "lower.tri")) plot(1) else plot.new() } par(pp) #### Example (3): Plot the upper triangle with par(mfcol = ...) pp <- par(mfcol = c(4, 4)) for(i in 1:16){ if(i %in% par_tri(mf = c(4, 4), type = "lower.tri")) plot(1) else plot.new() } par(pp) #### Example (4): Plot the lower triangle with par(mfcol = ...) pp <- par(mfcol = c(4, 4)) for(i in 1:16){ if(i %in% par_tri(mf = c(4, 4), type = "upper.tri")) plot(1) else plot.new() } par(pp) }