Add annotation box to grid of ggplot objects

I am preparing a grid of 37 ggplots using the grid.arrange function. To save space currently taken by the axis labels and to add some information like Sys.time() I would add a box to the lower right of the graphics grid.

A minimal example using the mtcars data can be found below. The real data will cover very different ranges on x axis to facetting is not an option.

Is there a way to add a “textbox” as shown in the *.pdf below within R to add further info using e.g. cat or print? I already looked at the Any hint would be highly appreciated.

# load needed libraries
library(ggplot2)
library(gridExtra)

# Set loop counter and create list to store objects
imax=37
plist <- list() 

# loop to generate 37 ggplot objects
# the real example covers different ranges on x-axis so facetting
# is not an option
for(i in 1:imax){
  p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_line()  + ggtitle(i)
  plist[i] <- p
}

# print to pdf in A3 format
pdf(file="out.pdf",width=16.5,height=11.7)
do.call(grid.arrange,c(plist,main="Main Title",sub="Subtitle"))
dev.off()

The output generated by above script


Download add.annotation.box.to.grid.of.ggplot.objects.zip
Direct Link


Download


Download add.annotation.box.to.grid.of.ggplot.objects.zip
Mediafire


Download


Download add.annotation.box.to.grid.of.ggplot.objects.zip
Hugefiles


Download


Download add.annotation.box.to.grid.of.ggplot.objects.zip
KeepFile


Download


Download add.annotation.box.to.grid.of.ggplot.objects.zip
Google Drive


Download

Both comments and pings are currently closed.

Comments are closed.