Graphics 如何将R图形打印到多页PDF和多个PDF?
我知道Graphics 如何将R图形打印到多页PDF和多个PDF?,graphics,r,plot,Graphics,R,Plot,我知道 pdf("myOut.pdf") 将在R中打印为PDF。如果我想怎么办 在PDF文件的新页面上创建一个打印后续图形的循环(附加到末尾) 创建一个循环,将后续图形打印到新的PDF文件(每个文件一个图形) 我不太明白 附加到同一文件(每页一个绘图): 每个循环的新文件: for (i in 1:10){ pdf(paste("myOut",i,".pdf",sep="")) plot(...) dev.off() } 你看了帮助(pdf)了吗 用法: pdf(file =
pdf("myOut.pdf")
将在R中打印为PDF。如果我想怎么办
我不太明白 附加到同一文件(每页一个绘图): 每个循环的新文件:
for (i in 1:10){
pdf(paste("myOut",i,".pdf",sep=""))
plot(...)
dev.off()
}
你看了帮助(pdf)了吗
用法:
pdf(file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),
width, height, onefile, family, title, fonts, version,
paper, encoding, bg, fg, pointsize, pagecentre, colormodel,
useDingbats, useKerning)
论据:
file: a character string giving the name of the file. For use with
'onefile=FALSE' give a C integer format such as
'"Rplot%03d.pdf"' (the default in that case). (See
'postscript' for further details.)
对于1),将onefile保持为默认值TRUE。几个绘图进入同一个文件
对于2),将onefile设置为FALSE并选择一个C整数格式的文件名,R将创建一组文件
pdf(file = "Location_where_you_want_the_file/name_of_file.pdf", title="if you want any")
plot() # Or other graphics you want to have printed in your pdf
dev.off()
您可以在pdf中绘制任意数量的内容,这些绘图将添加到不同页面的pdf中。
dev.off()关闭与文件的连接,将创建pdf,您将看到类似的内容
> dev.off()
null device 1
您甚至不需要文件名上的paste()——R也可以为您这样做;看看我的答案。你怎么能在每一页中包括几个情节?例如,一页中有5个绘图,下一页中有5个绘图。我尝试在命令
plot
之前包含par(mfrow=c(5,1))
,但我只得到每个绘图(在本例中为10个绘图)显示在10页中,但大小与函数par
中定义的尺寸相同,在本例中为5行1列。谢谢你advance@Ruben. 您应该在par(mfrow=c(5,1))之前调用pdf()(即:不在相反方向)。您还可以考虑增加PDFE()边距中的宽度和高度。希望这能有所帮助。如果您使用网格布局,如何转到下一个PDF页面?例如,您准备了一些GGPlot,将它们放在多页PDF的p1上的视口中,但是如何让下一个视口转到第2页。。。3.等
> dev.off()
null device 1