Combining and arranging plots"

knitr::opts_chunk$set(collapse = TRUE, fig.width = 7, fig.height = 5, fig.align = "center")
library(deeptime)
# Load ggplot2
library(ggplot2)
# Load ggtree
library(ggtree)
# Load paleotree for some example data
library(paleotree)
data(RaiaCopesRule)
## The history of arranging and combining plots Combining multiple plots together into figures is a key component of developing publishable data visualizations. Many other packages provide ways to combine and arrange plots. For example, the `gridExtra` package has the [`grid.arrange()` function](https://cran.r-project.org/package=gridExtra/vignettes/arrangeGrob.html) which allows the user to arrange plots in fairly complex layouts. However, the main drawback (for most cases) of this function is that the components of the plots (axes, labels, panels, etc.) are not aligned. The [`ggarrange()` function](https://cran.r-project.org/package=egg/vignettes/Overview.html#arranging-and-aligning-multiple-plots) in the `egg` package uses a 3x3 decomposition of the individual plots to align some of the plot components. The central cells correspond to the core panels, surrounded by axes, legends, etc. ## Arranging plots with deeptime __deeptime__ expands on this functionality with `ggarrange2()` to perform 7x7 decomposition of individual plots, as shown below. This ensures that more components of the individual plots are aligned with one another (e.g., the axis labels, the axis tick labels). The central cell corresponds to the plot panel(s), the rectangle of cells around that corresponds to the axes, the rectangle of cells around that corresponds to the axis titles, and the rectangle of cells around that corresponds to legends. wzxhzdk:2 ## Combining plots With this 7x7 decomposition process, it becomes very simple to combine plots into single figures with properly aligned components. wzxhzdk:3 You can chain calls to `ggarrange2()` to accomplish highly complex combinations and arrangements: wzxhzdk:4 You can also accomplish complex plot layouts by supplying a matrix of integers to the `layout` argument, like with the base R `layout()` function. This can be used to insert empty plots or change the order of plots. Note that repeating a number will duplicate a plot, not expand it across multiple plot spots. wzxhzdk:5 ## Other resources for arranging plots Note that I provide no guarantee that `ggarrange2()` solves every problem when arranging plots. The following other options may also be very useful: - The `{cowplot}` package has the `cowplot::plot_grid()` function which accomplishes many of the same features as `ggarrange2()`. - The `{patchwork}` has very intuitive tools for combining and arranging plots (e.g, using mathematical symbols).


Try the deeptime package in your browser

Any scripts or data that you put into this service are public.

deeptime documentation built on Feb. 16, 2023, 10:59 p.m.