Title: | Infrastructure to Assemble Multi-Panel Figures (from Grobs) |
---|---|
Description: | 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'). |
Authors: | Johannes Graumann [cre, aut], Richard Cotton [aut] |
Maintainer: | Johannes Graumann <[email protected]> |
License: | GPL (>= 3) |
Version: | 2.1.6 |
Built: | 2024-11-06 06:37:09 UTC |
Source: | CRAN |
Checks that the input is of class multipanelfigure
and has the
appropriate attributes.
assert_is_multipanelfigure(x)
assert_is_multipanelfigure(x)
x |
Object to check. |
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
This data was used to create Supplementary Figure 4e of Billing 2016 (see references).
A data frame with 81 rows and the following columns:
A factor with three levels naming genes that have interesting properties.
A numeric vector of positive intensities of proteins corresponding to the genes as determined by mass spectrometry.
A factor with three levels indicating the type of stem cell experimented on. "ESC" means embryonic stem cell; "ESC-MSC" means mesenchymal stem cell derived from an embryonic stem cell; "BM-MSC" means mesenchymal stem cell derived from bone marrow.
The region of the cell experimented on. "CH" means chromatin, "Cyt" means cytosol, "Nuc" means nucleus.
An integer specifying the experimental replicate.
The interaction of StemCellType, Organelle and Replicate.
A data frame of genes corresponding to protein intensities as measured by mass spectrometry proteomics experiments on embryonic and mesenchymal stem cells.
Billing AM, Ben Hamidane H, Dib SS, et al. Comprehensive transcriptomic and proteomic characterization of human mesenchymal stem cells reveals source specific cellular markers. Scientific Reports. 2016;6:21507. doi:10.1038/srep21507.
Article text available at: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4746666
Supplementary figures available at: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4746666/bin/srep21507-s1.pdf
ggplot2::ggplot(billing2016_suppfig4e, ggplot2::aes(Experiment, Intensity)) + ggplot2::geom_bar(stat = "identity") + ggplot2::geom_vline(xintercept = seq(3.5, 24.5, 3), linetype = "dotted") + ggplot2::facet_wrap(~ GeneName) + ggplot2::xlab(NULL) + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1, size = 4))
ggplot2::ggplot(billing2016_suppfig4e, ggplot2::aes(Experiment, Intensity)) + ggplot2::geom_bar(stat = "identity") + ggplot2::geom_vline(xintercept = seq(3.5, 24.5, 3), linetype = "dotted") + ggplot2::facet_wrap(~ GeneName) + ggplot2::xlab(NULL) + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1, size = 4))
This data was used to create Supplementary Figure 4g of Billing 2016 (see references).
A matrix with 13 rows and 9 columns. Rows represent genes, columns represent experiments and are split by:
The type of stem cell experimented on. "ESC" means embryonic stem cell; "ESC-MSC" means mesenchymal stem cell derived from an embryonic stem cell; "BM-MSC" means mesenchymal stem cell derived from bone marrow.
The experimental replicate.
Values in the matrix are intensities of proteins coresponding to the genes, as measured by mass spectrometry.
A matrix of log base 10 protein intensities as measured by mass spectrometry proteomics experiments on embryonic and mesenchymal stem cells.
Billing AM, Ben Hamidane H, Dib SS, et al. Comprehensive transcriptomic and proteomic characterization of human mesenchymal stem cells reveals source specific cellular markers. Scientific Reports. 2016;6:21507. doi:10.1038/srep21507.
Article text available at: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4746666
Supplementary figures available at: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4746666/bin/srep21507-s1.pdf
color_scale <- grDevices::cm.colors(25) heatmap( billing2016_suppfig4g, margins = c(12, 5), col = color_scale, cexRow = 0.5, cexCol = 0.4)
color_scale <- grDevices::cm.colors(25) heatmap( billing2016_suppfig4g, margins = c(12, 5), col = color_scale, cexRow = 0.5, cexCol = 0.4)
Capture a plot drawn using base graphics as a grid grob
.
capture_base_plot(expr)
capture_base_plot(expr)
expr |
A expression that draws a plot using base graphics. |
An object of class gTree
.
A side effect of this function is that plots get drawn twice: once as a base plot, and secondly as a grid plot.
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
p <- capture_base_plot(hist(rnorm(1000), seq(-4, 4, 0.2))) grid::grid.draw(p) # If the plot takes multiple lines to draw, then wrap the code in braces. p2 <- capture_base_plot({ par(las = 1) plot(1:5) title("One to five") }) grid::grid.draw(p2)
p <- capture_base_plot(hist(rnorm(1000), seq(-4, 4, 0.2))) grid::grid.draw(p) # If the plot takes multiple lines to draw, then wrap the code in braces. p2 <- capture_base_plot({ par(las = 1) plot(1:5) title("One to five") }) grid::grid.draw(p2)
A convenience function adding graphical objects to a
gtable
constructed by multi_panel_figure
.
fill_panel( figure, panel, row = "auto", column = "auto", label = NULL, label_just = c("right", "bottom"), panel_clip = c("on", "off", "inherit"), scaling = c("none", "stretch", "fit", "shrink"), allow_panel_overwriting = FALSE, verbose = TRUE, ... )
fill_panel( figure, panel, row = "auto", column = "auto", label = NULL, label_just = c("right", "bottom"), panel_clip = c("on", "off", "inherit"), scaling = c("none", "stretch", "fit", "shrink"), allow_panel_overwriting = FALSE, verbose = TRUE, ... )
figure |
Object of classes |
panel |
Single |
row |
|
column |
|
label |
Single |
label_just |
Justification for the label within the interpanel spacing
grob to the top-left of the panel content grob. Passed to
|
panel_clip |
Should the display of panel contents be clipped at the
panel borders? See |
scaling |
Only used when importing image files. Either "none" to preserve the dimensions of an image, "stretch" to make it fit the panels, "fit" to shrink or enlarge it so that it fills one dimension of the panels while preserving the height to width ratio, or "shrink which does the same but won't enlarge it. |
allow_panel_overwriting |
A logical value. If |
verbose |
A logical value. Reduces verbosity if |
... |
Additional arguments. Used to deal with deprecated arguments
|
Currently supported as panel-representing objects (panel
) are
ComplexHeatmap Heatmap
or
HeatmapList
objects.
ggplot2 ggplot
objects.
lattice trellis.object
s.
Single character
objects representing URLs or paths to
image formats accessible by ImageMagick
as used through
magick
, which will be read and placed into panels
as requested.
Native resolution is determined from attributes in the file. If the attributes are
not present, then the DPI is determined by the the
multipanelfigure.defaultdpi
global option, or 300 if this has not been
set.
lattice-generated trellis.object
s are converted
to grob
s using grid.grabExpr(print(x))
, as are Heatmap
and HeatmapList
s from ComplexHeatmap - the side effects of
which with respect to plot formatting are not well studied.
If the row
argument is "auto", then the first row with
a free panel is used.
If the column
argument is "auto", then the first column in the
row with a free panel is used.
Returns the gtable
object fed to it
(figure
) with the addition of the panel
.
Johannes Graumann, Richard Cotton
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
# Not testing - slow grid graphics makes CRAN timing excessive # Create the figure layout (figure <- multi_panel_figure( width = c(30,40,60), height = c(40,60,60,60), panel_label_type = "upper-roman")) # Fill the top-left panel using a grob object directly a_grob <- grid::linesGrob(arrow = grid::arrow()) figure %<>% fill_panel(a_grob) # Add a ggplot object directly to the top row, second column. # The panels are chosen automatically, but you can achieve the same effect # using column = 2 a_ggplot <- ggplot2::ggplot(mtcars, ggplot2::aes(disp, mpg)) + ggplot2::geom_point() figure %<>% fill_panel(a_ggplot) # Bitmap images are added by passing the path to their file. image_files <- system.file("extdata", package = "multipanelfigure") %>% dir(full.names = TRUE) %>% magrittr::set_names(basename(.)) # Add the JPEG to the top row, third column figure %<>% fill_panel(image_files["rhino.jpg"], column = 3) # Add the PNG to the second and third row, first and second column figure %<>% fill_panel( image_files["Rlogo.png"], row = 2:3, column = 1:2) # Add the TIFF to the second row, third column figure %<>% fill_panel( image_files["unicorn.svg"], row = 2, column = 3) # lattice/trellis plot objects are also added directly Depth <- lattice::equal.count(quakes$depth, number=4, overlap=0.1) a_lattice_plot <- lattice::xyplot(lat ~ long | Depth, data = quakes) # Add the lattice plot to the third row, third column figure %<>% fill_panel( a_lattice_plot, row = 3, column = 3) # Incorporate a gList object (such as produced by VennDigram) if(requireNamespace("VennDiagram")) { a_venn_plot <- VennDiagram::draw.pairwise.venn(50, 30, 20, ind = FALSE) # Add the Venn diagram to the fourth row, firstd column figure %<>% fill_panel( a_venn_plot, row = 4, column = 1) } # Incorporate a base plot figure a_base_plot <- capture_base_plot( heatmap( cor(USJudgeRatings), Rowv = FALSE, symm = TRUE, col = topo.colors(16), distfun = function(c) as.dist(1 - c), keep.dendro = TRUE, cexRow = 0.5, cexCol = 0.5)) # Add the heatmap to the fourth row, second column figure %<>% fill_panel( a_base_plot, row = 4, column = 2) # Incorporate a ComplexHeatmap figure require(ComplexHeatmap) mat = matrix(rnorm(80, 2), 8, 10) mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) rownames(mat) = letters[1:12] colnames(mat) = letters[1:10] ht = Heatmap(mat) a_complex_heatmap <- ht + ht + ht # Add the ComplexHeatmap to the fourth row, third column (figure %<>% fill_panel( a_complex_heatmap, row = 4, column = 3))
# Not testing - slow grid graphics makes CRAN timing excessive # Create the figure layout (figure <- multi_panel_figure( width = c(30,40,60), height = c(40,60,60,60), panel_label_type = "upper-roman")) # Fill the top-left panel using a grob object directly a_grob <- grid::linesGrob(arrow = grid::arrow()) figure %<>% fill_panel(a_grob) # Add a ggplot object directly to the top row, second column. # The panels are chosen automatically, but you can achieve the same effect # using column = 2 a_ggplot <- ggplot2::ggplot(mtcars, ggplot2::aes(disp, mpg)) + ggplot2::geom_point() figure %<>% fill_panel(a_ggplot) # Bitmap images are added by passing the path to their file. image_files <- system.file("extdata", package = "multipanelfigure") %>% dir(full.names = TRUE) %>% magrittr::set_names(basename(.)) # Add the JPEG to the top row, third column figure %<>% fill_panel(image_files["rhino.jpg"], column = 3) # Add the PNG to the second and third row, first and second column figure %<>% fill_panel( image_files["Rlogo.png"], row = 2:3, column = 1:2) # Add the TIFF to the second row, third column figure %<>% fill_panel( image_files["unicorn.svg"], row = 2, column = 3) # lattice/trellis plot objects are also added directly Depth <- lattice::equal.count(quakes$depth, number=4, overlap=0.1) a_lattice_plot <- lattice::xyplot(lat ~ long | Depth, data = quakes) # Add the lattice plot to the third row, third column figure %<>% fill_panel( a_lattice_plot, row = 3, column = 3) # Incorporate a gList object (such as produced by VennDigram) if(requireNamespace("VennDiagram")) { a_venn_plot <- VennDiagram::draw.pairwise.venn(50, 30, 20, ind = FALSE) # Add the Venn diagram to the fourth row, firstd column figure %<>% fill_panel( a_venn_plot, row = 4, column = 1) } # Incorporate a base plot figure a_base_plot <- capture_base_plot( heatmap( cor(USJudgeRatings), Rowv = FALSE, symm = TRUE, col = topo.colors(16), distfun = function(c) as.dist(1 - c), keep.dendro = TRUE, cexRow = 0.5, cexCol = 0.5)) # Add the heatmap to the fourth row, second column figure %<>% fill_panel( a_base_plot, row = 4, column = 2) # Incorporate a ComplexHeatmap figure require(ComplexHeatmap) mat = matrix(rnorm(80, 2), 8, 10) mat = rbind(mat, matrix(rnorm(40, -2), 4, 10)) rownames(mat) = letters[1:12] colnames(mat) = letters[1:10] ht = Heatmap(mat) a_complex_heatmap <- ht + ht + ht # Add the ComplexHeatmap to the fourth row, third column (figure %<>% fill_panel( a_complex_heatmap, row = 4, column = 3))
grob
DimensionsConvenience functions extracting dimensions from
grob
objects.
figure_width(grob, unit_to = "mm") figure_height(grob, unit_to = "mm")
figure_width(grob, unit_to = "mm") figure_height(grob, unit_to = "mm")
grob |
A |
unit_to |
Single numeric
objects are returned.
Johannes Graumann
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
multi_panel_figure
, save_multi_panel_figure
# Get dimensions of a grid grob a_circle <- grid::circleGrob(x = 15, y = 30, r = 15, default.unit = "mm") figure_height(a_circle) figure_width(a_circle) # Use the unit_to arg to convert units figure_height(a_circle, unit_to = "in") figure_width(a_circle, unit_to = "cm") # Get dimensions of a multi-panel figure figure <- multi_panel_figure(width = 55, height = 55, rows = 2, columns = 2) figure_height(figure) figure_width(figure) # ggsave defaults to measuring dimensions in inches width <- figure_width(figure, unit_to = "in") height <- figure_height(figure, unit_to = "in") tmp_file <- tempfile(fileext = ".png") ggplot2::ggsave( tmp_file, gtable::gtable_show_layout(figure), width = width, height = height ) # Not testing due to use of external software utils::browseURL(tmp_file)
# Get dimensions of a grid grob a_circle <- grid::circleGrob(x = 15, y = 30, r = 15, default.unit = "mm") figure_height(a_circle) figure_width(a_circle) # Use the unit_to arg to convert units figure_height(a_circle, unit_to = "in") figure_width(a_circle, unit_to = "cm") # Get dimensions of a multi-panel figure figure <- multi_panel_figure(width = 55, height = 55, rows = 2, columns = 2) figure_height(figure) figure_width(figure) # ggsave defaults to measuring dimensions in inches width <- figure_width(figure, unit_to = "in") height <- figure_height(figure, unit_to = "in") tmp_file <- tempfile(fileext = ".png") ggplot2::ggsave( tmp_file, gtable::gtable_show_layout(figure), width = width, height = height ) # Not testing due to use of external software utils::browseURL(tmp_file)
A TIFF photograph of Farouq the cat in a washing machine. CC-BY-SA 4.0 Richard Cotton, 2014.
An image file.
A JPEG photograph of a greater one-horned rhinoceros (Rhinoceros unicornis) taken in Kaziranga National Park, Assam, India. CC-BY-SA 4.0 Janette Cotton, 2016.
An SVG picture of a fat, pink winged unicorn. CC-BY-SA 4.0 Sara Lendal, 2016.
A PNG of the R logo. CC-BY-SA 4.0 The R Foundation, 2016.
## Not run: figure <- multi_panel_figure( width = c(60, 40, 40), height = c(40, 40, 40) ) image_files <- system.file("extdata", package = "multipanelfigure") %>% dir(full.names = TRUE) %>% setNames(basename(.)) figure %>% fill_panel(image_files["farouq.tiff"]) %>% fill_panel(image_files["unicorn.svg"], column = 2:3) %>% fill_panel(image_files["rhino.jpg"], row = 2:3) %>% fill_panel(image_files["Rlogo.png"], column = 2:3, row = 2:3) ## End(Not run)
## Not run: figure <- multi_panel_figure( width = c(60, 40, 40), height = c(40, 40, 40) ) image_files <- system.file("extdata", package = "multipanelfigure") %>% dir(full.names = TRUE) %>% setNames(basename(.)) figure %>% fill_panel(image_files["farouq.tiff"]) %>% fill_panel(image_files["unicorn.svg"], column = 2:3) %>% fill_panel(image_files["rhino.jpg"], row = 2:3) %>% fill_panel(image_files["Rlogo.png"], column = 2:3, row = 2:3) ## End(Not run)
A convenience function building gtable
-based
infrastructure for the assembly of multipanel figures.
multi_panel_figure( width = "auto", columns = NULL, height = "auto", rows = NULL, row_spacing = NaN, column_spacing = NaN, unit = "mm", figure_name = "FigureX", panel_label_type = c("upper-alpha", "lower-alpha", "decimal", "upper-roman", "lower-roman", "upper-greek", "lower-greek", "none"), ... )
multi_panel_figure( width = "auto", columns = NULL, height = "auto", rows = NULL, row_spacing = NaN, column_spacing = NaN, unit = "mm", figure_name = "FigureX", panel_label_type = c("upper-alpha", "lower-alpha", "decimal", "upper-roman", "lower-roman", "upper-greek", "lower-greek", "none"), ... )
width |
|
columns |
Single |
height |
|
rows |
Single |
row_spacing |
|
column_spacing |
|
unit |
Single |
figure_name |
Single |
panel_label_type |
A string specifying the marker style for the panel labels used for automated annotation. Defaults to uppercase Latin letters. |
... |
Argument to accomodate deprecated arguments |
The gtable
may be constructed in two ways:
Based on explicit width/height definitions for individual panels.
Based on total figure/gtable
dimensions given by
width
and height
together with the number of columns
and rows
requested.
The function automatically inserts whitespace of width
column_spacing
before column panels (and of height
row_spacing
before row panels), which has to be considered
for the total dimensions of the resulting gtable
. Width
of the gtable
in the former case, for example may be
calculated
while width of resulting panels in the latter table construction approach may be calculated
width
, height
, column_spacing
and
row_spacing
may be defined numerically or as
unit
objects.
Earlier implementations used parameters widhts
and heights
as
synonyms for width
and height
with length greater than one.
These parameters have been deprecated. They continue to work, but produce
a warning.
The two approaches to gtable
construction require
interdepending parameter sets:
Requires width
and
height
of lengths corresponding to the number of columns/rows
requested. Excludes the use of columns
and rows
.
gtable
/figure dimensions:Requires width
, columns
, height
and rows
of
length 1.
Returns an object of class multipanelfigure
as well as
gtable
object with the following additional attributes:
multipanelfigure.panelsFree
:A logical
matrix
with the dimensions of the gtable
indicating occupancy of the panels in the table.
multipanelfigure.panellabelsfree
:A character
vector
indicative of the panel_labels
still available.
multipanelfigure.unit
:A single character
object storing the corresponding value given during object creation.
Johannes Graumann
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
fill_panel
for more examples of filling panels
figure_width
for inspecting figure dimensions
capture_base_plot
for including plots created using base graphics
gtable
for the underlying structure of a figure
## Not run: # Figure construction based on the dimensions of the current device figure1 <- multi_panel_figure( columns = 2, rows = 2, figure_name = "figure1") # With no panels, printing shows the layout figure1 # Figure construction based on overall dimensions figure2 <- multi_panel_figure( width = 100, columns = 4, height = 90, rows = 6, figure_name = "figure2") # Still no panels ... figure2 # Figure construction based on individual panel dimensions (figure3 <- multi_panel_figure( width = c(40,30), height = c(40,60), row_spacing = c(5, 1), column_spacing = c(0, 10), figure_name = "figure3")) # A more involved example including filling and printing to device ... # Make a simple ggplot object to fill panels ggp <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() # Fill panels # ggplots and lattice plot objects are added directly # The default position is the top-left panel figure3 <- fill_panel(figure3, ggp) # Raster images are added by passing the path to their file jpg <- system.file("extdata/rhino.jpg", package = "multipanelfigure") figure3 <- fill_panel(figure3, jpg, column = 2) # Plots can take up multiple panels figure3 <- fill_panel(figure3, ggp, row = 2, column = 1:2) # Plot to appropriately sized png device tmpFile <- tempfile(fileext = ".png") ggplot2::ggsave( tmpFile, figure3, width = figure_width(figure3, "in"), height = figure_height(figure3, "in")) message( paste0("Now have a look at '",tmpFile,"' - nicely sized PNG output.")) \donttest{ # Not testing due to use of external software utils::browseURL(tmpFile) } ## End(Not run)
## Not run: # Figure construction based on the dimensions of the current device figure1 <- multi_panel_figure( columns = 2, rows = 2, figure_name = "figure1") # With no panels, printing shows the layout figure1 # Figure construction based on overall dimensions figure2 <- multi_panel_figure( width = 100, columns = 4, height = 90, rows = 6, figure_name = "figure2") # Still no panels ... figure2 # Figure construction based on individual panel dimensions (figure3 <- multi_panel_figure( width = c(40,30), height = c(40,60), row_spacing = c(5, 1), column_spacing = c(0, 10), figure_name = "figure3")) # A more involved example including filling and printing to device ... # Make a simple ggplot object to fill panels ggp <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() # Fill panels # ggplots and lattice plot objects are added directly # The default position is the top-left panel figure3 <- fill_panel(figure3, ggp) # Raster images are added by passing the path to their file jpg <- system.file("extdata/rhino.jpg", package = "multipanelfigure") figure3 <- fill_panel(figure3, jpg, column = 2) # Plots can take up multiple panels figure3 <- fill_panel(figure3, ggp, row = 2, column = 1:2) # Plot to appropriately sized png device tmpFile <- tempfile(fileext = ".png") ggplot2::ggsave( tmpFile, figure3, width = figure_width(figure3, "in"), height = figure_height(figure3, "in")) message( paste0("Now have a look at '",tmpFile,"' - nicely sized PNG output.")) \donttest{ # Not testing due to use of external software utils::browseURL(tmpFile) } ## End(Not run)
Functions that are no longer used or have been superceded by functions with underscore-separated names.
addPanel( figure, ... ) capturebaseplot( ... ) multipanelfigure( ... ) simplegrobheight( ... ) simplegrobwidth( ... )
addPanel( figure, ... ) capturebaseplot( ... ) multipanelfigure( ... ) simplegrobheight( ... ) simplegrobwidth( ... )
figure |
Object of classes |
... |
Arguments to functions you shouldn't use. |
Prints and object of class multipanelfigure
.
## S3 method for class 'multipanelfigure' print(x, newpage = TRUE, ...)
## S3 method for class 'multipanelfigure' print(x, newpage = TRUE, ...)
x |
An object of class |
newpage |
Logical. If |
... |
Passed from other print methods. |
The input x
is invisibly returned, but the method is mostly
invoked for the side effect of printing the plot to the current device.
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
p <- lattice::xyplot(dist ~ speed, cars) figure <- multi_panel_figure( width = 100, height = 100, rows = 1, columns = 1 ) # With no panels, printing shows the layout print(figure) figure <- fill_panel(figure, p) # After a panel is added, printing shows the plot. print(figure) # shows plot
p <- lattice::xyplot(dist ~ speed, cars) figure <- multi_panel_figure( width = 100, height = 100, rows = 1, columns = 1 ) # With no panels, printing shows the layout print(figure) figure <- fill_panel(figure, p) # After a panel is added, printing shows the plot. print(figure) # shows plot
A convenience function wrapping ggsave
from ggplot2 for easy saving of gtable
objects
constructed by multi_panel_figure
taking into account the
table's dimensions.
save_multi_panel_figure(figure, filename, dpi = 300, ...)
save_multi_panel_figure(figure, filename, dpi = 300, ...)
figure |
Object of classes |
filename |
Single |
dpi |
Single |
... |
Other arguments passed to |
Plot dimensions are determined using
figure_height
and figure_width
.
The Device type to use is guessed from the filename
extension.
Currently supported are "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff",
"png", "bmp", "svg" or "wmf" (windows only).
Johannes Graumann
Graumann, J., and Cotton, R.J. (2018). multipanelfigure: Simple Assembly of Multiple Plots and Images into a Compound Figure. Journal of Statistical Software 84. doi: 10.18637/jss.v084.c03
ggsave
, figure_width
,
figure_height
# Create the figure layout (figure <- multi_panel_figure( width = c(30,40,60), height = c(40,60,60,60), panel_label_type = "upper-roman")) # Fill the top-left panel using a grob object directly a_grob <- grid::linesGrob(arrow = grid::arrow()) figure %<>% fill_panel(a_grob) ## Not run: # Save the figure figure %>% save_multi_panel_figure( filename = paste0( tempfile(), ".png")) ## End(Not run)
# Create the figure layout (figure <- multi_panel_figure( width = c(30,40,60), height = c(40,60,60,60), panel_label_type = "upper-roman")) # Fill the top-left panel using a grob object directly a_grob <- grid::linesGrob(arrow = grid::arrow()) figure %<>% fill_panel(a_grob) ## Not run: # Save the figure figure %>% save_multi_panel_figure( filename = paste0( tempfile(), ".png")) ## End(Not run)