marrangeGrob in the gridExtra arranges grobs (usually ggplots in my case) in rows, columns and pages. It also numbers the pages.
require(ggplot2)
require(plyr)
require(gridExtra)
p <- function(plotdata) {
x <- ggplot(plotdata, aes(wt, mpg)) +
geom_point() +
ggtitle(plotdata$gear[1])
return(x)
}
all <- dlply(mtcars, .(gear), p)
allarranged <- do.call(marrangeGrob, c(all, nrow=1, ncol=2))
ggsave("multipage.pdf", allarranged, width=12)
That's a silly but reproducible example.
Now inspect the output of str(allarranged[[1]]) to reveal the objects of the page numbers. Reduced to the essentials, they're here:
[[1]]
$ children :List of 5
..$GRID.frame.1925:List of 6
.. ..$ children :List of 5
.. .. ..$ GRID.cellGrob.1927:List of 10
.. .. .. ..$ children :List of 1
.. .. .. .. ..$ GRID.text.1845:List of 11
.. .. .. .. .. ..$ label : chr "page 1 of 2"
I made up the first few lines there because I'm having trouble writing the output of str() to file. The point stands, though. $label is the problem-child of many grandparents. There are also several $labels per arrangelist (arrangeList is the output class of arrangeGrob).
Once you've figured out where the $labels are, then this works:
allarranged[[1]]$children$GRID.frame.1770$children$GRID.cellGrob.1772$children$GRID.text.1690$label <- NULL
But how to predict that whole tree, or recurse through it looking for $labels? If that weren't such an interesting problem I'd probably just contact the gridExtra maintainer.
You need to pass top=NULL to marrangeGrob.
all <- dlply(mtcars, .(gear), p)
allarranged <- do.call(marrangeGrob, c(all, nrow=1, ncol=2, list(top=NULL) ))
ggsave("multipage.pdf", allarranged, width=12)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With