【发布时间】:2010-11-26 14:16:39
【问题描述】:
我知道
pdf("myOut.pdf")
将打印到 R 中的 PDF。如果我想怎么办
创建一个循环以在 PDF 文件的新页面上打印后续图表(附加到末尾)?
创建一个循环,将后续图表打印到新的 PDF 文件(每个文件一个图表)?
【问题讨论】:
我知道
pdf("myOut.pdf")
将打印到 R 中的 PDF。如果我想怎么办
创建一个循环以在 PDF 文件的新页面上打印后续图表(附加到末尾)?
创建一个循环,将后续图表打印到新的 PDF 文件(每个文件一个图表)?
【问题讨论】:
你看过帮助(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("myOut.pdf")
for (i in 1:10){
plot(...)
}
dev.off()
每个循环的新文件:
for (i in 1:10){
pdf(paste("myOut",i,".pdf",sep=""))
plot(...)
dev.off()
}
【讨论】:
plot 之前包含par(mfrow=c(5,1)),但我只得到每个图(在本例中为10 个图)出现在10 页中,但尺寸的大小在函数par 中定义,在此案例5行1列。提前致谢
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
【讨论】: