multi_panel_grid: Arranges a group of ggplot2 plots or grid::grob's into...

multi_panel_gridR Documentation

Arranges a group of ggplot2 plots or grid::grob's into multiple panels.

Description

Function creates a figure with title and arranges multiple plots/grobs across a given number of rows and columns. The function depends on the grid, gtable, and ggplotify packages.

Usage

multi_panel_grid(
  layout,
  title = NULL,
  title_fontsz = 22,
  plot_titles = NULL,
  y_tick_width = 0.5,
  cell_width = 8,
  cell_height = 8,
  do_grid = FALSE,
  display_plot = TRUE
)

Arguments

layout

A named list containing a list for plot objects or grobs "plots", row locations "rows" vector, column locations "cols" vector. This argument is required.

title

A string that sets the title of the figure.

title_fontsz

A numeric that sets the title's font size. The default is 14.

plot_titles

A character vector with the same length as the number of plot objects that defines each of their titles.

y_tick_width

A numeric that sets the width of the vertical column containing the y axis tick labeling. The default is 0.5 cm and may be increased when a wider labeling is needed.

cell_width

A numeric that sets the cell widths in the gtable in cm

cell_height

A numeric that sets the cell widths in the gtable in cm

do_grid

A logical which if TRUE will arrange the plot objects in a straight row/column order without considering their scale and label components.

display_plot

A logical that if TRUE will display the plot, otherwise a ggplot2 object is returned.

Details

The function goes beyond just placing a group of plots across a grid of rows and columns. It is somewhat opinionated in favor of common titling/labeling and scaling that make sense for all the plots and provide the ability to compare. The function has a title parameter that is assumed appropriate for all the plots–any titles/subtitles among the plots themselves will be removed. The first left y-axis scaling the function comes across will be used for all the plots. Similarly the first bottom x-axis scaling the function comes across will be assumed appropriate for all the plots. The first legend that is found is assumed right for all the plots and will be placed at the top in a horizontal direction. Of course none of these sub-elements among the plots need to exist and you are back to simply a grid of plots.

As an example of defining the layout argument, layout has three named elements: "plots", "rows", and "cols". "plots" is a list() of ggplot2 plot objects; "rows" defines the row number for each plot and "cols" defines the column number for each plot. If we have two plots with both plots on a single row then "rows" = c(1,1) and "cols" = c(1,2).

Value

A ggplot2 object if display_plot is FALSE.

Author(s)

Rick Dean


deandevl/RplotterPkg documentation built on Feb. 1, 2024, 8:02 p.m.