plotting a list of grobs

你。 提交于 2019-12-04 13:06:51

Here's my interpretation of your script, if it's not the intended result you may want to use some bits and pieces to make your question reproducible.

library(grid)
library(gridExtra)
library(ggplot2)

morletPlots <- replicate(5, ggplot(), simplify = FALSE)
rawplot <- replicate(5, ggplot(), simplify = FALSE)

glets <- lapply(morletPlots, ggplotGrob)
graws <- lapply(rawplot, ggplotGrob)

rawlet <- function(raw, let, heights=c(4,1)){
  g <- rbind(let, raw)
  panels <- g$layout[grepl("panel", g$layout$name), ]
#  g$heights <- grid:::unit.list(g$heights) # not needed
  g$heights[unique(panels$t)] <- lapply(heights, unit, "null")
  g
}

combined <- mapply(rawlet, raw = graws, let=glets, SIMPLIFY = FALSE)

grid.newpage()
grid.arrange(grobs=combined, ncol=2)

Edit I can't resist this mischievous hack to colour the plots for illustration; feel free to ignore it.

palette(RColorBrewer::brewer.pal(8, "Pastel1"))
ggplot.numeric = function(i) ggplot2::ggplot() + 
  theme(panel.background=element_rect(fill=i))

morletPlots <- lapply(1:5, ggplot)
rawplot <- lapply(1:5, ggplot)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!