Infrastructure to Assemble Multi-Panel Figures (from Grobs)

Tools to create a layout for figures made of multiple panels, and to fill the panels with base, 'lattice', 'ggplot2' and 'ComplexHeatmap' plots, grobs, as well as content from all image formats supported by 'ImageMagick' (accessed through 'magick').

Project Status: Active - The project has reached a stable, usable state and is being actively developed. Is the package on CRAN? Build Status Build status

Tools to create a layout for figures made of multiple panels, and to fill the panels with base, lattice and ggplot2 plots, grobs, and bitmap images as supported by ImageMagick (through the package magick).


To install the package, you first need the devtools package.


Then you can install the multipanelfigure package using


Specifying a layout

Layouts are matrices of panels that contains plots, grobs or images. Create them with the multi_panel_figure function.

You can specify the total width and height of the figure (the default unit is millimetres):

figure1 <- multi_panel_figure(
  width = 180, height = 180,
  columns = 3, rows = 3)

Or you can specify widths and heights of individual columns and rows.

figure2 <- multi_panel_figure(
  width = c(20, 30, 40),
  height = c(10, 20, 30))

When no panels are filled, printing the figure (by typing its name) displays the layout. Notice that by default a 5 mm spacer is included between rows and between columns. (This can be adjusted using multi_panel_figure's row_spacing and column_spacing arguments.)


An image of the layout of an empty multi-panel figure.

Adding panels

Plots and images are added into the figure by filling panels using fill_panel.

lattice plot variables are added directly. The syntax is cleanest using magrittr pipes:

a_lattice_plot <- xyplot(height ~ age, Loblolly)
figure1 %<>% fill_panel(a_lattice_plot)

ggplot2 plots variables are also added directly. In this case, to put it in the second column from the left (top row), specify the left_panel argument.

a_ggplot <- ggplot(Loblolly, aes(age, height)) + geom_point()
figure1 %<>% fill_panel(a_ggplot, column = 2)

Plots created using base graphics must be converted to grid-based plots and captured using capture_base_plot.

a_base_plot <- capture_base_plot(
  with(Loblolly, plot(age, height))
figure1 %<>% fill_panel(a_base_plot, column = 3)

grid grobs are also added directly. Plots and images can be made to span multiple panels by defining starting and stopping columns using column and/or starting and stopping rows using row. The following example adds the grob to the second and third rows from the top (first column).

a_grob <- linesGrob(arrow = arrow())
figure1 %<>% fill_panel(a_grob, row = 2:3)

Bitmap images (such as JPEG, PNG, and TIFF images) are added via a string giving their location: either a path to a location on disk, or a URL.

figure1 %<>% fill_panel(
  column = 2:3,
  row = 2:3)

Once panels have been added to the figure, printing it displays the figure.


An image of the filled multi-panel figure, containing several plots and images.


2.0.2 Clean out leftowvers from vignette 'knitr'ing (only found on CRAN buildservers). 2.0.1 Fix an erroneous (duplicated) 'VignetteIndexEntry' as requested by the CRAN maintainers; 2.0.0 Major version increment: switch all handling of external graphics to 'magick' (access to 'ImageMagick') 1.1.0 As caTools is being archived (n.o response of maintainer to CRAN requests), caTools-dependent gif support is temporarily dropped. 0.8.4 Added support for importing GIFs into panels. Different scaling options for image panels. 0.8.3 Bug fix release to support latest version of rsvg package. 0.8.2 First public release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


2.1.2 by Johannes Graumann, 2 years ago

Browse source code at

Authors: Johannes Graumann [cre, aut] , Richard Cotton [ctb]

Documentation:   PDF Manual  

GPL (>= 3) license

Imports assertive.base, assertive.files, assertive.numbers,, assertive.types, ggplot2, grid, gridGraphics, gtable, magick, magrittr, stats, stringi, utils

Suggests ComplexHeatmap, grDevices, lattice, roxygen2, VennDiagram, knitr, rmarkdown, markdown

Suggested by flippant.

See at CRAN