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

R 3.5.0 and spaces in file paths

The R 3.5.0 update introduced a bug, at least under MS-Windows. File paths containing spaces are truncated at the first space character, leading to errors like:


Fatal error: cannot open file 'C:\Users\<user-name>\AppData\Roaming\WinEdt': No such file or directory

for a file path like 'C:\\Users\\<user-name>\\AppData\\Roaming\\WinEdt Team\\WinEdt 10\\<file-name>' or 'C:/Users/<user-name>/AppData/Roaming/WinEdt Team/WinEdt 10/<file-name>'.

This bug breaks, among other things, the ‘RManager’ extension of the editor WinEdt. I would expect this to cause various other surprising errors after upgrading to R 3.5.0.

This bug is already corrected in the patched version of R 3.5.0 available through CRAN. For Windows, the most recent patched R version can be downloaded from https://cran.r-project.org/bin/windows/base/rpatched.html and installed as usual.

R 3.4.0 released

R 3.4.0 was released some days ago. A compatibility update to RStudio is also available.

The repositories at this site and obviously also at CRAN now contain package binary distributions for R 3.4.x and R 3.3.x.

One major change in this release is that the JIT (just in time) compiler is enabled by default. I have not done any benchmarking yet.

I have written a page explaining how to upgrade your R installation.

The code examples in my book Learn R …as you learnt your mother tongue continue to work as expected. However not all the package updates for R 3.4.0 are yet in CRAN. In package ‘gganimate’ function gg_animate() has been renamed gganimate().

The code examples in our book R for Photobiology: Theory and recipes for common calculations run without problems. Due to recent updates to the packages in my R for Photobiology Suite, used in the book examples, fewer warnings than earlier are triggered.