Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reusing chunks that include plotting with knitr .Rmd

Tags:

r

knitr

When a chunk that includes plotting is reused the plots are not referenced properly, i.e. they are identical for both chunks though they are supposed to be different. What can I do about it?

## Test

```{r}
col <- "black"
```

```{r chunk1}
plot(0, col=col)
```

```{r}
col <- "red"
```

```{r chunk1}
```
like image 632
Mark Heckmann Avatar asked Jun 18 '12 10:06

Mark Heckmann


1 Answers

You should use a different label like

```{r chunk2, ref.label='chunk1'}
```

See http://yihui.name/knitr/demo/reference/

like image 153
Yihui Xie Avatar answered Sep 19 '22 21:09

Yihui Xie