我还有另一个非常基本的问题,需要使用 R 在四开本中引用图形,但我无法在网上找到答案。
所以,这是一个非常小的可重现示例;
---
title: "Untitled"
format: pdf
editor: visual
---
```{r fig-plot, warning=FALSE, message=FALSE, echo=FALSE}
library(tidyverse)
mtcars <- mtcars
ggplot(mtcars, aes(x = mpg, y = cyl)) +
geom_point()
As can be seen in @fig-plot
从输出中可以看出,图下方有一个文本,这是我不希望有的。如何通过破坏绘图的交叉引用来删除它?感谢您事先的关注。
fig
您的 reprex 缺少代码块上的关闭栅栏。修复此问题后,只需删除
fig
部分即可删除图下方的标题文本。您也不需要在 YAML frontmatter 中使用 fig.cap: false
。
块标签中的
fig
部分标记四开本这是一个图形。请参阅文档此处。通过省略 fig
,标题将被删除。这并不能解决损坏的交叉引用,但从问题中不清楚你想用它做什么。
此外,根据文档,可以将 chunk options 向下移动到块本身中。
---
title: "Untitled"
format: pdf
editor: visual
---
```{r}
#| label: plot
#| warning: false
#| message: false
#| echo: false
library(tidyverse)
mtcars <- mtcars
ggplot(mtcars, aes(x = mpg, y = cyl)) +
geom_point()
```
输出
fig-cap
设置为空白另一种方法是将块选项设置为具有空白的图形标题。这将保留图形标签,并且交叉引用将正常工作。但是,如果希望删除所有图形标签信息(这将破坏交叉引用),选项 #1 可能更好。
```{r}
#| label: fig-plot
#| fig-cap: ""
#| warning: false
#| message: false
#| echo: false
library(tidyverse)
mtcars <- mtcars
ggplot(mtcars, aes(x = mpg, y = cyl)) +
geom_point()
```
输出: