我无法将页码添加到PDF中。下面是我如何插入页/图:R - 将页码添加到PDF
pdf(file = pdfFilePath , width = 11 , height = 8.5 )
for (...) {
grid.newpage()
pushViewport(viewport(layout = grid.layout(2 , 2)))
... print 4 plots ....
}
onefile似乎被命名页码文件,但我想要的页码出现在同一个文件。
编辑
我修改@加文的代码示例产生混合图形类型,以获得页码的工作版本:
require(ggplot2)
pdf(file = "FILE_PATH_TO_SAVE_PDF_HERE" , width = 11 , height = 8.5 )
par(oma = c (4 , 4 , 4 , 4) , mar=c(4 , 0 , 2 , 0) )
plot(0:11 , type = "n", xaxt="n", yaxt="n", bty="n", xlab = "", ylab = "" )
mtext(side = 3 , line = 0 , outer = TRUE , cex = 1.5 , family="mono" , "Title")
grid.newpage()
p1 <- ggplot(data.frame(X = 1:10, Y = runif(10)), aes(x = X, y = Y)) +
geom_point()
vplayout <- function(x, y) {
viewport(layout.pos.row = x, layout.pos.col = y)
}
pushViewport(viewport(layout = grid.layout(2, 2)))
print(p1, vp = vplayout(1,1))
print(p1, vp = vplayout(1,2))
print(p1, vp = vplayout(2,1))
print(p1, vp = vplayout(2,2))
mtext("1" , side = 1 , line = 3 , outer = TRUE , cex = .8 , family="mono" )
dev.off()
这不求求你为什么不想使用Sweave或Sweave-like系统的一个问题生成你的PDF。你甚至不需要使用LaTeX - 如果LaTeX是进入的障碍,你可以使用odfWeave并将其转换为PDF。 – 2011-04-20 19:42:50
...如果这是基础图形,我只需添加一个外边距('par(oma = c(3,0,0,0))')并通过'title(xlab =“pagenum”, outer = TRUE)'调用或'mtext(“pagenum”,side = 1,outer = TRUE)'调用。但是,我不知道有足够的网格图形来了解与之等效的步骤。 – 2011-04-20 19:51:59
@Gavin - 我需要再看一下Sweave,但说实话,这似乎是一个非常基本的场景。如果R让我能够将多个页面打印到PDF,那么我希望能够立即添加页码。 – SFun28 2011-04-20 19:52:23