Labeling panels in R

This is a brief tutorial on how to add labels to plots outside the plotting area in both basic plots and for ggplot2. I use this to label panels “A”, “B”, “C”, etc. but figuring out how to do this was surprisingly difficult. Here is my solution:

screenshot-2016-12-21-16-15-49

Here are the plots generated using the basic plot function:

screenshot-2016-12-21-16-20-05

basic plot with panels labeled “A” and “B” in R

…and the second example with basic plot. In this plot the top margin is smaller:

screenshot-2016-12-21-16-21-09

basic plot with panels labeled “A” and “B” in R

basic plot with panels labeled “A” and “B” in R

Here are the plots using ggplot2:

screenshot-2016-12-21-16-21-52

ggplot with panels labeled “A” and “B” in R

…and the vertical version:

screenshot-2016-12-21-16-22-32

ggplot with panels labeled “A” and “B” in R

If you want to tweak the exact location of the plot labels, this is easily done in ggplot2. You simply adjust the x and y values by very small increments, making sure to stay between 0 and 1.

Leave a comment