The following R-Markdown code doesn’t work with Knitr:
Create a bimodal toy distribution.
```{r}
a = c(rnorm(100, 5, 2), rnorm(100, 15, 3))
```
Set up the graphics device.
```{r fig.show='hide'}
plot(0, type = 'n', xlim = c(0, 20), ylim = c(0, 0.2), axes = FALSE)
```
Plot the density.
```{r}
polygon(density(a), col = 'black')
```
Knitr assumes that a graphics device ends at the end of an R code block, and closes the device. Consequently, I cannot reuse (in the third code block) a previously set up graphics device.
My question is simple: how can I make this work?