Reputation: 1131
When using RMarkdown + Knitr to make an HTML output of my code/plots, the plot images always appear as expected in RStudio with the correct width/height sizes specified in the chunk options, but if I then use Knitr to put everything together in an HTML document, the plots are all resized to a smaller default it seems.
Viewing each plot separately in a new tab shows their large size as desired but why can't this be the way they are shown in the HTML. Any setting I can change for this?
Upvotes: 2
Views: 2470
Reputation: 7770
There is a difference between fig.width
and out.width
, and likewise between fig.height
and out.height
. The fig.*
control the size of the graphic that is saved, and the out.*
control how the image is scaled in the output.
For example, the following .Rmd file will produce the same graphic twice but displayed with different width and height.
---
title: "Example graphic"
---
```{r echo = FALSE, fig.width = 14, fig.height = 9, out.width = "588", out.height = "378"}
library(ggplot2)
ggplot(mpg, aes(x = year, y = cyl)) + geom_point()
```
```{r echo = FALSE, fig.width = 14, fig.height = 9, out.width = "1026", out.height = "528"}
library(ggplot2)
ggplot(mpg, aes(x = year, y = cyl)) + geom_point()
```
Upvotes: 2