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

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.

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

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

Book and package: Learn R …as you learnt your mother tongue

Book cover

Book cover

Book draft of 2017-05-14 and ‘learnrbook’ package 0.0.2.

My book titled Learn R …as you learnt your mother tongue is gradually approaching completion, but the text is not yet polished. Today’s milestone is that the first version of the companion R package has been accepted for distribution through CRAN.

In the draft version I uploaded today, published as earlier ones through Leanpub, approximately 95% of the book content is included. Today’s version differs from earlier ones in that as now the original datasets and files used in examples are now in package ‘learnrbook’, the example code has been edited to make use of it. The package is since yesterday in CRAN. The updated version of the book also tracks improvements in version 0.2.15 of my package ‘ggpmisc’, which is since today in CRAN.

The PDF of this updated draft of the book is available at for whatever price you would like to pay for it (including for free). However, paying even as little as 1€ for your copy would go a long way towards supporting the expenses of running this web site.