How to have same plot appearance in the RStudio Rmarkdown inline visualization and the knitted html?

When making plots in a Rmarkdown document with inline visualization, I can use fig.width and fig. heigth to adjust the plot size so that all proportions look good, including fonts. But then when I knit the html file, the plot will come out with different proportions, often with very enlarged fonts. So to make the plot looks as desired, I have to experiment and knit repeatedly, which is quite troublesome. I wonder if there is any chunk option I can set so that the knitted html figure will look the same as the inline. I have tried fig.width/height, out.width/heigth, dpi, fig.retina, without success.

Looking for a solution, I found an old StackOverflow question about this, without answer, suggesting that this may only happen in retina displays (r - Inline plot size and knitted plot size don't agree in RStudio on retina display - Stack Overflow).

A quick reproducible example is:

```{r, fig.height=2, fig.width=3}
library(ggplot2)

ggplot(mtcars, aes(x = mpg, y = hp, color = cyl)) + 
  geom_point() + 
  ggtitle("I want the relative size of my font and plot just like this")
```

I am using RStudio 1.4 in a Retina Macbook.

I appreciate the help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.