【问题标题】:ggplot list of plots to one pdf with different page layoutsggplot 绘图列表到一个具有不同页面布局的pdf
【发布时间】:2016-03-17 08:17:30
【问题描述】:

我想制作一个包含多页 ggplots 的单个 pdf。使用gridExtra,我还可以构建具有m x n 布局的绘图页面(m 绘图行,n 绘图列)。

ggsave 函数允许我写一页图,即使是使用 gridExtra 构建的具有m x n 布局的图。

使用arrangeGrob 甚至可以将多个页面ggsave 转换为一个pdf,只要每个页面具有相同的m x n 布局。

我想知道如何ggsave 列出具有不同页面布局的地块?例如,我有一个列表,l,长度为 3 代表 3 页。

l[[1]] 是一个具有2 x 2 布局的页面,并且有 4 个绘图

l[[2]]2 x 1,有 2 个地块

l[[3]] 只是1 x 1

我如何破解ggsave 以便将列表l 写入1 个具有不同布局的3 页的pdf 文件?绘图应以横向显示,因此该命令通常具有以下形式

ggsave("multipage.pdf", do.call(arrangeGrob, myplots[[i]]), width=11, height=8.5)

【问题讨论】:

    标签: r ggplot2 gridextra


    【解决方案1】:

    你可以使用与marrangeGrob相同的类技巧,

    library(ggplot2)
    library(gridExtra)
    pl <- lapply(1:7, function(i) ggplot() + ggtitle(i))
    
    ppl <- list(p1 = arrangeGrob(grobs=pl[1:4]),
                p2 = arrangeGrob(grobs=pl[5:6]),
                p3 = arrangeGrob(grobs=pl[7]))
    
    class(ppl) <- c("arrangelist", class(pl))
    
    ggsave("multipage.pdf", ppl)
    

    【讨论】:

      猜你喜欢
      • 2016-02-07
      • 2016-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      相关资源
      最近更新 更多