Package ‘patchwork’

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.

# install.packages("devtools")
devtools::install_github("thomasp85/patchwork")

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.

library(ggspectra)
library(patchwork)
p <- autoplot(sun.spct) / 
  autoplot(polyester.spct, range = c(280, 800)) / 
  autoplot(sun.spct * polyester.spct)
png("three-plots.png", height = 800, width = 600)
print(p) & theme_bw()
dev.off()

from Data to Viz (external link)

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!

To access the website and/or to buy the printed poster visit from Data to Viz.

 

gginnards 0.0.1

Package ‘gginnards’ is now in CRAN. This new package contains functions removed from ‘ggpmisc’ at version 0.3.0. The package was split as the audience the different functions are intended for is different: ‘gginnards’ is for those needing tools for programming ‘ggplot2’ extensions or wanting to learn how ggplots work. Most importantly, the functions now in ‘gginnards’ cannot be expected to survive with unchanged functionality across major updates to ‘ggplot2’, and importing them into other packages is strongly discouraged.

In contrast the functions retained in ‘ggpmisc’ and the new ones added in version 0.3.0 are intended for users creating plots for data analyses and reports. I am committed to maintaining ‘ggpmisc’ in the long term while striving to retain backwards compatibility as much as possible.

Documentation web site at http://docs.r4photobiology.info/gginnards/ includes all help pages, with output from all examples, and vignettes in HTML format.
NOTE: The package is available through CRAN.

Please raise issues concerning bugs or enhancements to this package through Bitbucket https://bitbucket.org/aphalo/gginnards/issues