R标记链接到图形

R标记链接到图形,r,r-markdown,pandoc,R,R Markdown,Pandoc,我正在创建一个包含多个图表的报告。我想在随附的文本中提及它们。我尝试了以下方法: --- title: "Test" output: pdf_document --- Figure \ref{test} is a graph ```{r test, fig.cap="This is a graph"} df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30)

我正在创建一个包含多个图表的报告。我想在随附的文本中提及它们。我尝试了以下方法:

---
title: "Test"
output: 
  pdf_document
---
Figure \ref{test} is a graph

```{r test, fig.cap="This is a graph"}

df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
                 y = rnorm(30))

ggplot(df, aes(x = gp, y = y)) +
   geom_point()
```

This is text to follow the diagram

\pagebreak

This is another page but can still link to Figure \ref{test}

有没有一种默认的方法可以在R markdown中做到这一点,而不必自己去做

我想我在这里找到了一个答案-

如果我理解正确的话,使用此代码似乎可以提供我认为您需要的行为

---
title: "Test"
output: 
  pdf_document
---
Figure \ref{fig:plot} is a graph

```{r plot-ref, fig.cap = "This is a graph\\label{fig:plot}"}

library('ggplot2')

df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
                 y = rnorm(30))

ggplot(df, aes(x = gp, y = y)) +
   geom_point()
```

This is text to follow the diagram

\pagebreak

This is another page but can still link to Figure \ref{fig:plot}
---
标题:“测试”
输出:
pdf\U文件
---
Figure\ref{fig:plot}是一个图形
```{r plot ref,fig.cap=“这是一个图形\\标签{fig:plot}”
库('ggplot2')

df我想我在这里找到了答案-

如果我理解正确的话,使用此代码似乎可以提供我认为您需要的行为

---
title: "Test"
output: 
  pdf_document
---
Figure \ref{fig:plot} is a graph

```{r plot-ref, fig.cap = "This is a graph\\label{fig:plot}"}

library('ggplot2')

df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
                 y = rnorm(30))

ggplot(df, aes(x = gp, y = y)) +
   geom_point()
```

This is text to follow the diagram

\pagebreak

This is another page but can still link to Figure \ref{fig:plot}
---
标题:“测试”
输出:
pdf\U文件
---
Figure\ref{fig:plot}是一个图形
```{r plot ref,fig.cap=“这是一个图形\\标签{fig:plot}”
库('ggplot2')
df