bestRowColumnSetting: best nrow/ncol setting for n plots

View source: R/main.R

bestRowColumnSettingR Documentation

best nrow/ncol setting for n plots

Description

Number of rows and columns in an optimal plot grid for n plots

Usage

bestRowColumnSetting(n, target.ratio = 1, device.ratio = NULL)

Arguments

n

number of plots to be placed in a matrix of equally sized plot cells

target.ratio

desired height/width ratio within each plot (ignoring margins). Default: 1

device.ratio

desired height/width ratio in the output device. Default: kwb.plot:::getPlotRegionRatio()

Value

named vector of two elements with the first element (nrow) representing the number of rows and the second element (ncol) representing the number of columns for an optimal plot grid to be used for n plots in the current plot region

Examples

  # save current graphical parameter setting
  old.par <- graphics::par(no.readonly = TRUE)
  
  for (i in 2:5) {
    
    graphics::par(mfrow = kwb.plot::bestRowColumnSetting(i))
    
    for (j in 1:i) {
      plot(seq_len(j), main = paste0("j = ", j, "/", i))
    }      
  }
  
  # restore graphical parameter setting
  graphics::par(old.par)  


KWB-R/kwb.plot documentation built on Oct. 2, 2023, 10:16 p.m.