R Notebook:在报表中包含图形并保存图形 [英] R Notebook: Include figures in report and save plots
问题描述
我正在使用R笔记本,我希望我的绘图在代码运行时自动保存到磁盘,以及内联显示.
I'm using an R Notebook and I'd like my plots to automatically save to disk when the code is run, as well as display inline.
knitr:在报告中包含数字*和*将数字输出到单独的文件中解决了R Markdown的问题,但给出的解决方案不适用于R Notebook. R笔记本电脑有类似的选择吗?
knitr: include figures in report *and* output figures to separate files addresses this for R Markdown but the solution given doesn't work for an R Notebook. Is there a similar option for R Notebooks?
推荐答案
这最终为我工作(请参阅@TCZhang对我的问题的回答此处):
This is what eventually worked for me (see @TCZhang 's answer to my question here):
除了设置@DonJ建议的编织块fig.path="figures/"
选项外,请尝试设置output: html_document
,或者仅按顶部Preview [Notebook]
按钮旁边的下拉菜单,然后按Knit to HTML
.我认为这不起作用的原因是您的输出设置为output: html_notebook
.
In addition to setting the knitr chunk fig.path="figures/"
option suggested by @DonJ, try setting output: html_document
, or just press the dropdown next to the Preview [Notebook]
button at the top and press Knit to HTML
. I think the reason this isn't working is that your output is set to output: html_notebook
.
我不知道为什么当文档为R Notebook格式时,这种方法不能特别有效.我也希望这对于output: html_notebook
是否有效,因此这可能是我们需要使用RStudio或knitr打开的问题.
I don't know why this doesn't work specifically when the doc is in R Notebook format. I would also prefer if this worked for output: html_notebook
, so it might be an issue we need to open with RStudio or knitr.
这篇关于R Notebook:在报表中包含图形并保存图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!