Specify height and width of ggplot graph in Rmarkdown knitr output

user6571411 picture user6571411 · Sep 22, 2016 · Viewed 39k times · Source

I have created a plot with ggplot2 where the x-axis labels are not readable unless the plot is larger than default. When viewing in Rstudio I am able to resize dynamically. When saving with ggsave() I am able to specify height and width. How would I do this within the Rmarkdown file so that the output contains a plot of the desired size?

Answer

user6571411 picture user6571411 · Sep 22, 2016

You can specify height and width in the code chunks

```{r, fig.width=10,fig.height=11}
df %>% ggplot(aes(x = x, y = y)) + geom_point()
```