简体   繁体   中英

reusing chunks that include plotting with knitr .Rmd

When a chunk that includes plotting is reused the plots are not referenced properly, ie 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}
```

You should use a different label like

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM