Operators defined in package ‘patchwork’ can be used to combine multiple plots created with package ‘ggplot2’ or extensions to it, such as my own ‘ggpmisc’ and ‘ggspectra’. (The site ggplot2 extensions showcases at the moment more than 40 extensions to ‘ggplot2’.)
Package ‘patchwork’ has been developed by Thomas Lin Pedersen, and being relatively new, it is not yet in CRAN. It can be installed from the public Git repository at Github.
The ‘ggplot2’ package provides a strong API for sequentially building up a plot, but does not concern itself with composition of multiple plots. ‘patchwork’ is a package that expands the API to allow for arbitrarily complex composition of plots by providing mathmatical operators for combining multiple plots. Other packages that address this need (but with a different approach) are ‘gridExtra’ and ‘cowplot’.
From the package’s DESCRIPTION.
Package ‘ggspectra’ provides function multiplot() for this purpose, but this function is minimalistic, with its most important handicap in its inability to independently align the plotting areas and axis labels of the composed plots.
An example using the operators / and & from ‘patchwork’ follows.
As our package ‘photobiologyInOut’ (versions >= 0.4.15) supports the automatic import of the files returned by the Quick TUV Calculator, we show here how to produce such files, and link to an example showing how to import and plot them in R.
from data to Viz is a new web site related to data analysis and R. Its aim is to make it easier to choose among different types of data visualisations. It looks beautiful, is easy to navigate, includes “trees” displaying a classification of visualizations and multiple individual examples with the corresponding R code. Highly recommended!
Improve the automatic positioning of labels generated by stat_poly_eq(), most notably when grouping is in effect and with facets with free scales. The values passed as argument to the new parameters label.x.npc and label.y.npc are in normalized parent coordinates with fractional values relative to the total dimension of the x and y scales. Character strings “right”, “center” and “left” for x and “top”, “center”, and “bottom” for y are also recognized. The behaviour of parameters label.x and label.y remains unchanged and they override any arguments passed through label.x.npc and label.y.npc. However, passing absolutes coordinates through the old parameters will be rarely needed.
Add stat_fit_deviations() for easily highlighting residuals in plots of fitted models, and stat_fit_residuals() for easily plotting residuals in plots matching plots of “lm” fits plotted with stat_smooth() even with grouping or facets. At the moment these two stats support lm() fits only.
Add stat_fit_glance() which uses package broom::glance() to produce a one-row data frame summarizing the model fit object. This gives maximum flexibility in model function choice at the expense of very frequently having to set aesthetics explicitly.
Add preliminary version of stat_fit_augment() which uses broom::augment() to enhance the data frame received as input with variables related to a model fit. At the moment functionality is very limited.
NOTE: This version of the package is now available from the R and R-test repositories at this site.