MyNixOS website logo
Description

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

multipanelfigure

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

Installation

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

install.packages("devtools")

Then you can install the multipanelfigure package using

devtools::install_bitbucket("graumannlabtools/multipanelfigure")

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

library(multipanelfigure)
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.)

figure1

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:

library(lattice)
library(magrittr)
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.

library(ggplot2)
library(magrittr)
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).

library(grid)
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(
  "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Persian_Cat_%28kitten%29.jpg/657px-Persian_Cat_%28kitten%29.jpg",
  column = 2:3,
  row = 2:3)

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

figure1

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

Metadata

Version

2.1.6

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows