ggsave behavior is differs between IDE and source script

When the following code is run interactively with the RStudio IDE, the font size does not scale with the resolution. In other words, the font "shrinks" at 300 dpi. However, if this code is sourced the font size appears to scale appropriately with the resolution.

Is this a bug or am I doing something wrong?

figure01 = ggplot(iris) +
  geom_boxplot(aes(x = Species, y = Petal.Length)) +
  scale_x_discrete("Species") +
  scale_y_continuous("Petal length (mm)")

# Resolution is 300
ggsave(filename = "figure01_300.png", plot = figure01,
       width = 80, height = 80, dpi = 300, units = "mm")

# Resolution is 96
ggsave(filename = "figure01_96.png", plot = figure01,
       width = 80, height = 80, dpi = 96, units = "mm")

I am using Version 1.4.1106 for x86_64-pc-linux-gnu.
R version 4.0.3, tidyverse version 1.3.0

2021/3/7 Update: Apparently there is no problem when running RStudio in Windows 10.
2021/3/8 Update: The problem I observed on Linux was resolved, because the behavior disappeared.

Hi @Greg_Nishihara,
Since you are using the png() output device via ggsave(), you could try specifying the pointsize=12 argument to fix the text label size. I can't test this as I'm not on Linux.

@DavoWW Thank you for your comment. Adding pointsize = 12 did not appear to do anything. However, what was more perplexing was that the problem I mentioned in the original post did not re-occur.

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.