R ggplot2,dlply:在n页上打印

R ggplot2,dlply:在n页上打印,r,pdf,ggplot2,R,Pdf,Ggplot2,我正在尝试创建多个绘图(基于一个方面),以便根据需要打印到尽可能多的pdf页面中。这些曲线图代表了作者在其单个出版物中获得的引文数量。 这里是一个玩具数据集: Publications <-data.frame(Year=c(1,2,1,2,3,4,5),Publication=c(rep("A"),rep("B"),rep("C"),rep("D"),rep("E"),rep("F"),rep("G")),Author=c(rep("John",2),rep("Michael",5)),

我正在尝试创建多个绘图(基于一个方面),以便根据需要打印到尽可能多的pdf页面中。这些曲线图代表了作者在其单个出版物中获得的引文数量。 这里是一个玩具数据集:

Publications <-data.frame(Year=c(1,2,1,2,3,4,5),Publication=c(rep("A"),rep("B"),rep("C"),rep("D"),rep("E"),rep("F"),rep("G")),Author=c(rep("John",2),rep("Michael",5)),Citations=c(5,6,4,7,2,3,8))
最后,我用刻面变量“Author”拆分样本,并将其保存在pdf中,如下所示:

require(plyr)
plots <-dlply(Publications, .(Author), function(x) a %+% x + 
                facet_wrap_paginate(Author ~ Publication, ncol = 1, nrow = 3))
pdf()
plots
dev.off()
plots$plots
require(plyr)

绘图根据ggforce的帮助页面

“通常这将被放入一个循环中,以逐个呈现所有页面”

因此,我们需要计算页数,并继续进行for循环

另一种选择是marrangeGrob

require(plyr)
plots <- dlply(Publications,
               .(Author, Publication), "%+%", e1 = a)
gridExtra::marrangeGrob(grobs = plots, nrow=3, ncol=1)
require(plyr)
阴谋
require(plyr)
plots <- dlply(Publications,
               .(Author, Publication), "%+%", e1 = a)
gridExtra::marrangeGrob(grobs = plots, nrow=3, ncol=1)