Anouar
Anouar

Reputation: 301

How to refer to a figure in R markdown

I want to make a reference to a boxplot in R markdown code. I tried to make it on this way but I didn't success:

text text text ([Figure 1](#fig1)) text text text

{#fig1}
chunk:
:::
```r 
df$NF <- df$`non-failing heart (NF)`
df$F <- df$`failing heart (F)`
boxplot(df[3:4],
        data=df,
        cex.lab=0.65,
        xlab="Fig. 1 IRE binding activity for non-failing (NF) and failing (F) hearts.",
        ylab="IRE binding activity (%)",
        col="orange",
        border="brown",
        ylim = c(0, 120)
)
```

:::

My idea is to give an ID to the figure in the R code but I didn't know how.

Upvotes: 1

Views: 1217

Answers (1)

Thierry
Thierry

Reputation: 18487

Use bookdown. Then you can crossreference figures.

text text (fig. \@ref(fig:blabla))

```{r blabla, fig.cap = "caption"}
plot(1:2, 1:2)
```

See https://bookdown.org/yihui/bookdown/figures.html for more information

Upvotes: 1

Related Questions