保存并显示rmd文件中的图

问题描述 投票:4回答:1

我正在使用R markdown处理一个相当长的代码,分为块。绘图出现在适当的块下面。我想保持这种行为,但另外我想将它们保存到指定的文件夹。我尝试过这里列出的不同方法How to save a plot as image on the disk?(以及互联网上的其他地方),但似乎没有任何效果。 我可重复的例子:

png('cars_plot.png')
plot(cars)
dev.off()

此代码保存绘图,但不显示它(它只返回“null device 1”)。我也尝试了dev.print和dev.copy,结果相同。 先感谢您!澄清:我一个接一个地运行我的块,我不想将我的结果转换为pdf / html。所以knitr: include figures in report *and* output figures to separate fileschange where rmarkdown saves images generated by r code不回答我的问题。

r plot save r-markdown show
1个回答
0
投票

你总是可以在同一个降价块中将它绘制两次,如下所示:

图(汽车)

PNG( 'cars_plot.png')

图(汽车)

Dev.off()

© www.soinside.com 2019 - 2024. All rights reserved.