Skip to content

Instantly share code, notes, and snippets.

@baptiste
Last active February 17, 2020 20:02
Show Gist options
  • Save baptiste/eadeecd7d3756a7f294eb3cade8b0b17 to your computer and use it in GitHub Desktop.
Save baptiste/eadeecd7d3756a7f294eb3cade8b0b17 to your computer and use it in GitHub Desktop.
library(egg)
library(gridExtra)
library(ggplot2)
library(grid)
d <- data.frame(x=runif(10*7),
y=runif(10*7),
f1 = gl(7,10),
f2 = gl(3, 30, 7*10))
p <- ggplot(d, aes(x,y))+
facet_grid(f2~f1)+
geom_line()
ld <- split(d, d$f2)
lp <- lapply(ld, `%+%`, e1 = p)
ggarrange(plots=lp)
lg <- lapply(lp, egg::set_panel_size,
width=unit(4,'cm'), height=unit(1,'null'))
rows <- lapply(lg, function(x)
arrangeGrob(rectGrob(gp=gpar(col=NA)), x, nrow=1,
widths = unit.c(unit(1,'null'), sum(x$widths))))
grid.newpage()
grid.arrange(grobs = rows, ncol=1)
@baptiste
Copy link
Author

Screen Shot 2020-02-18 at 8 00 51 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment