2

It turns out that setting plot sizes on a Mac with retina display can be challenging. I am not referring to file sizes or resolutions that can be taken care of with the fig.retina setting (I have seen several questions about that), but the fact that the actual figure layout differs between the inline version of a an RMarkdown script and both an exported version with the same dimensions (using ggsave) as well as a knitted version. Even small figure dimensions appear gigantic inline on the screen while they export and knit correctly. So, the ratio between font size and "plot size" (or whatever it would be called) appears to change. If I run the code on an older (non-retina) Macbook or a PC, the inline figure sizes are as expected.

enter image description here

This is an example of what I mean. The specified figure dimensions were fig.width=4, fig.height=3.

Is there a way to get the inline graph dimensions match the knitted versions...?

Thanks y'all!

edit: code included, not sure how reproducible it is though, since it might only be relevant to users with retina or 4k displays:

---
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
```

```{r, fig.width=4, fig.height=3}
Pdata <- data.frame("X" = 1:10, "Y" = 1:10) # some data

ggplot(data = Pdata,aes(x = X,y = Y)) +
  geom_point() +
  theme_bw(base_size = 20) +
  labs(x = "Some stuff", y = "Some more stuff")
```
4
  • You should include a reproducible example. Nobody can help you if we don't know what you did. Nov 15, 2018 at 20:40
  • Hm. Maybe I'm the only one with this particular issue...
    – Rincewind
    Nov 20, 2018 at 16:46
  • Having the same issue on RStudio Version 1.4.1106 on Retina MacBook.
    – JG11235
    Apr 2, 2021 at 14:26
  • Maybe setting some elements (e.g. point size) relative to grDevices::dev.size() can help? Jan 4 at 20:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.