gpt4 book ai didi

r - 如何将绘图附加到现有 pdf 文件

转载 作者:行者123 更新时间:2023-12-02 19:15:12 25 4
gpt4 key购买 nike

我想在调用 dev.off() 后很长时间后将绘图附加到现有 pdf*。阅读 pdf() 帮助文件并阅读问答之后 herehere ,我很确定这不能在 R 中完成。但是,也许你们中一些聪明的人有一个我找不到的解决方案。

pdf("Append to me.%03d.pdf",onefile=T)
plot(1:10,10:1) #First plot (page 1)
dev.off()
pdf("Append to me.%03d.pdf",onefile=T)
plot(1:10,rep(5,10)) #Want this one on page 2
dev.off()

*这不是上面链接的问题的重复,因为我想在 pdf 设备关闭后附加到 pdf 文件。

最佳答案

您可以使用recordPlot将每个绘图存储在列表中,然后使用replayPlot将它们全部写入最后的pdf文件中。这是一个例子:

num.plots <- 5
my.plots <- vector(num.plots, mode='list')

for (i in 1:num.plots) {
plot(i)
my.plots[[i]] <- recordPlot()
}
graphics.off()

pdf('myplots.pdf', onefile=TRUE)
for (my.plot in my.plots) {
replayPlot(my.plot)
}
graphics.off()

关于r - 如何将绘图附加到现有 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13273611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com