as.grob function accepts plot function call as expression or formula, or a function that plots to an R graphics device. The plots can be generated by base graphics (p1, p2, p3) or grid (p4). If the plot function produce graphic object, it can be directly used as input (p5, can be trellis object by lattice package, meme object by meme package, upset object by ‘UpSetR’ package, etc.).

It will convert the plot to grob object, so that it can be compatible with grid system and related packages.

We can now use grid.draw to plot p1 and p2, and use pushViewport to embed plot inside another plot.

If you are not family with grid, you can use ggplot2 to do similar task (e.g. p8 in the below example).


All the plots that can be converted to grob are supported to be converted to ggplot object by using as.ggplot function.

Align plots

With all the plots converted to ggplot objects, we are able to align plots produced by ‘base’ and ‘grid’ graphic systems using cowplot or patchwork.