7
votes

I label my figures like this.

---
title: "xxx"
output: 
  pdf_document:
    fig_caption: true
---

And then in each chunk

```{r, fig.cap="some caption"}
qplot(1:5)
```

This works quite nicely. However in chunks where I plot multiple figures within a loop I can't specify a caption. This produces no caption at all:

```{r, fig.cap="another caption"}
qplot(1:5)
qplot(6:10)
```

How can I specify a figure that counts from the same number as the first chunk for each plot?

1

1 Answers

14
votes

You can use a fig.cap argument of length 2 (or the size of your loop):

```{r, fig.cap=c("another caption", "and yet an other")}
qplot(1:5)
qplot(6:10)
```