Flexible Layouts With The Patchwork Package In R

Bryan Jenks
Analytics Vidhya
Published in
6 min readAug 31, 2020

--

Patchwork is a package for the R programming language that simplifies data visualization layouts through a simple math-like syntax.

“The Composer of ggplots”

With Patchwork the task of combining and organizing ggplots is very easy and can produce ornate visualizations with simple code.

All charts here are made with sample data sets and are just used for example purposes.

Simple Chart Combinations

Vertically Stacked Charts

If i wanted to take a couple charts of mind and compare them next to each other either one above the other it may look something like this:

An Example of Code For a Top and Bottom Chart Combo With Patchwork

Looking at this code what we do is create 2 ggplots and assign each to their own variable, top and bottom respectively.

Conveniently named we can see where each is going to be placed in the final visual.

The simple Patchwork syntax is finding those 2 variables at the bottom and with a simple…

--

--

Bryan Jenks
Analytics Vidhya

Information Technology Associate with CA.gov, YouTuber, and perpetual student