R 循环遍历完整的脚本,找到所有生成的图并保存它们 [英] R loop through complete script, find all plots generated and save them

查看:90
本文介绍了R 循环遍历完整的脚本,找到所有生成的图并保存它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 R 时遇到以下问题,目前还没有找到解决方案:

I have the following problem using R and not found a solution so far:

我有一个脚本,可以在其中运行多个操作并生成一些图.最后,我想要一段很好的代码,可以自动将生成的所有图保存到当前工作目录中.到目前为止,我正在使用:

I have a script where I run several operation and generate some plots. At the end, I would like to have a nice piece of code that automatically saves all the plots generated into the current working directory. So far, I am using:

trellis.device(device="png", filename="Plot_A.png")打印(Plot_A)dev.off()

trellis.device(device="png", filename="Plot_A.png") print(Plot_A) dev.off()

这仅适用于一个特定的情节.现在我正在寻找某种 for 循环,它可以获取所有绘图并将它们与绘图名称一起保存为 png 文件

Which is working fine for just one specific plot. Now I am looking for some kind of for loop that takes all the plots and saves them with the name of the plot as a png file

推荐答案

不完全是答案,而是替代工作流程.

Not exactly an answer but an alternative workflow.

如果您要保存绘图以便在其他地方使用它,例如将它们包含在 Word 文档或演示文稿中,您可以将代码放入 RMarkdown 文档中并 knitr 以生成 html 或 doc包含代码生成的所有输出的文档,包括绘图.使用 RStudio,只需点击几下即可完成所有操作.

If you are saving your plots in order to use it somewhere else, for example to include them in a Word document or in a presentation, you could just put your code in an RMarkdown document and knitr it to generate an html or doc document with all the output generated by the code, including plots. With RStudio all that could be done with a few clicks.

从 Word 文档中获取所有绘图甚至可能比从 png 文件文件夹中获取更容易.

It may even be easier to take all plots from the Word document than from a folder of png files.

这篇关于R 循环遍历完整的脚本,找到所有生成的图并保存它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆