我会使用块选项 out.width 和 out.height 将最终输出中的绘图缩小到 0 x 0 尺寸。 (有关所有块选项,请参阅这个出色的文档:https://yihui.name/knitr/options/#plots)。
例如:
---
title: "SO Answer"
author: "duckmayr"
date: "9/24/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Here's how to make the figure with the caption but without the plot:
```{r pressure, fig.cap='Here is a figure caption.', out.width=0, out.height=0}
plot(pressure)
```
更新:绘图文件在哪里?
如果添加一行如
knitr::opts_chunk$set(fig.path = "figures/")
到上面的setup 块,绘图将保存在figures/ 子目录中。比如编织后
---
title: "SO Answer"
author: "duckmayr"
date: "9/24/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(fig.path = "figures/")
```
Here's how to make the figure with the caption but without the plot:
```{r pressure, fig.cap='Here is a figure caption.', out.width=0, out.height=0}
plot(pressure)
```
我可以看到~/figures/中的文件:
[duckmayr@duckmayr-pc ~]$ ls ~/figures/
pressure-1.png
(由于您要编织成 PDF,默认情况下,您的绘图图像也将保存为 PDF,而不是 PNG)。