【发布时间】:2021-04-20 09:00:21
【问题描述】:
R Markdown Cookbook 的This section 展示了如何创建绘图并稍后在文档中显示它:
---
output: bookdown::pdf_document2
---
We generate a plot in this code chunk but do not show it:
```{r cars-plot, dev='png', fig.show='hide'}
plot(cars)
```
After another paragraph, we introduce the plot:
`)
我的问题是我无法在文本中引用此图。见以下代码和输出:
---
output: bookdown::pdf_document2
---
We generate a plot in this code chunk but do not show it:
```{r cars-plot, dev='png', fig.show='hide'}
plot(cars)
```
Here's a reference to this plot: figure \@ref(fig:cars-plot).
After another paragraph, we introduce the plot:
`)
请注意,如果我立即显示该图,则参考效果很好:
---
output: bookdown::pdf_document2
---
We generate a plot in this code chunk but do not show it:
```{r cars-plot, fig.cap="A nice plot."}
plot(cars)
```
Here's a reference to this plot: figure \@ref(fig:cars-plot).
如何在稍后显示绘图但仍然可以引用它?我知道我可以简单地将块移动到我希望情节出现的位置,但这对我来说并不理想。
【问题讨论】:
-
用
[1](#fig:cars-plot)替换\@ref(fig:cars-plot)怎么样,即[link text](#ID)?更多信息here.
标签: r r-markdown bookdown