2

I would like to include a figure on a beamer slide produced by Rmarkdown / knitr. Setting the fig.width or fig.height options in the R code chunk changes the relative size of all plot elements (e.g. setting a smaller size makes fonts and geoms larger proportional to the plot area), but the plot still takes up most of the slide.

Instead, I would like to present a plot that takes up less area on the slide. How can I do that?

Note that this is a different question to this, which is asking about how to produce vector graphics. My figures are saved as pdf.

EDIT: after trying some more examples, it seems I just needed to be more extreme in my resizing and to manually adjust the base font size in the ggplot2 theme.

Sorry! My bad.

Reproducible example:

```{r logit, fig.width=1.5, fig.height=1.1}
library(ggplot2)
tmp <- data.frame(x = seq(-5, 5, length.out = 50))
tmp$y <- plogis(tmp$x)
plt <- ggplot(tmp, aes(x = x, y = y)) + 
  geom_line() + 
  xlab("Linear predictor") + ylab("Probability") + 
  theme_minimal(base_size = 8)
plt
```
tsawallis
  • 1,035
  • 4
  • 13
  • 26
  • You should post something reproducible. We don't know what `plt` or `myfig` is. The default `plot` function respects `fig.width` and `fig.height`. – user2554330 Nov 29 '16 at 14:29
  • In developing a minimal example I realised I was just not being extreme enough in resizing. Sorry. – tsawallis Nov 29 '16 at 16:08
  • That's one reason minimally reproducible examples are useful: it's pretty common that you solve your own problem while producing one. – user2554330 Nov 29 '16 at 19:51

0 Answers0