Multiple ggplots of different sizes

You can use nested arrangeGrob calls like this example: library(ggplot2) library(gridExtra) p <- ggplot(data.frame(x=1, y=1), aes(x,y)) + geom_point() grid.arrange( arrangeGrob( p, arrangeGrob(p, p, nrow=2), ncol=2 ,widths=c(2,1)), arrangeGrob(p, p ,p ,ncol=3, widths=rep(1,3)), nrow=2) Edit: gl <- lapply(1:9, function(ii) grobTree(rectGrob(),textGrob(ii))) grid.arrange( arrangeGrob(gl[[1]], do.call(arrangeGrob, c(gl[2:5], ncol=2)), nrow=1, widths=3:2), do.call(arrangeGrob, c(gl[6:9], nrow=1, list(widths=c(1,1,1,2)))), nrow=2, heights=c(2,1))

Saving grid.arrange() plot to file

grid.arrange draws directly on a device. arrangeGrob, on the other hand, doesn’t draw anything but returns a grob g, that you can pass to ggsave(file=”whatever.pdf”, g). The reason it works differently than with ggplot objects, where by default the last plot is being saved if not specified, is that ggplot2 invisibly keeps track of the … Read more

Removing one tableGrob when applied to a box plot with a facet_wrap

It would probably make sense to let annotation_custom access facetting info *; this trivial change seems to do the trick, library(ggplot2) library(grid) library(gridExtra) annotation_custom2 <- function (grob, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, data) { layer(data = data, stat = StatIdentity, position = PositionIdentity, geom = ggplot2:::GeomCustomAnn, inherit.aes = … Read more

set ggplot plots to have same x-axis width and same space between dot plot rows

library(gridExtra) library(grid) gb1 <- ggplot_build(dat1.plot) gb2 <- ggplot_build(dat2.plot) # work out how many y breaks for each plot n1 <- length(gb1$layout$panel_params[[1]]$y.labels) n2 <- length(gb2$layout$panel_params[[1]]$y.labels) gA <- ggplot_gtable(gb1) gB <- ggplot_gtable(gb2) g <- rbind(gA, gB) # locate the panels in the gtable layout panels <- g$layout$t[grepl(“panel”, g$layout$name)] # assign new (relative) heights to the panels, based … Read more

Plot over multiple pages

There are multiple ways to do the pagination: ggforce or gridExtra::marrangeGrob. See also this answer for another example. ggforce: library(ggplot2) # install.packages(“ggforce”) library(ggforce) # Standard facetting: too many small plots ggplot(diamonds) + geom_point(aes(carat, price), alpha = 0.1) + facet_wrap(~cut:clarity, ncol = 3) # Pagination: page 1 ggplot(diamonds) + geom_point(aes(carat, price), alpha = 0.1) + facet_wrap_paginate(~cut:clarity, … Read more