Specify Height and Width of Ggplot Graph in Rmarkdown Knitr Output

Knitr not displaying graph when out.width or out.height set

Instead of using knitr::knit() it is easier to use rmarkdown::render(). You can either call it directly

Rscript -e 'rmarkdown::render("file.Rmd")'

or indirectly using an example script from the littler package

render.r file.Rmd

on the command line.

Dynamic height and width for knitr plots

You can for example define the width in another chunk, then use it

```{r,echo=FALSE}
x <- data.frame(x=factor(letters[1:3]),y=rnorm(3))
len = length(unique(x$x))
```

```{r fig.width=len, fig.height=6}

plot(cars)
```


Related Topics



Leave a reply



Submit