Question

Can anyone help me in relation to passing (or setting global) par graphical parameters across chunks in knitr.

I have a large piece of R code with a loop that generates a plot at each iteration of the loop and prints each plot on the same page of a PDF (via par(mfrow=c(5,4)).

If I break up my code into knitr chunks to make it more manageable, the graphical parameters are lost each time I leave the chunk and I lose the ability to output several plots on the same PDF page.

Is there a way to pass graphical parameters across chunks or to set the parameters as global so that all chunks can access them.

No correct solution

OTHER TIPS

You can set the global.par knitr-option to TRUE like this:

```{r setup, include=FALSE}
opts_knit$set(global.par = TRUE)
```

Then set par in the next chunk and plot something:

```{r}
par(mfrow=c(5,4))
plot(something)
```

The same par-options will now be passed to the following chunks (until changed again).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top