font size shrinks with ggsave

116 views
Skip to first unread message

Jonathan Rubin

unread,
Aug 10, 2022, 6:55:55 AM8/10/22
to ggplot2
I have a few projects that use ggplot to create charts then ggsave to export as PNG. Recently the font sizes in the saved files have shrunk. See before/after for an example. Appearance in RStudio is correct. Nothing has changed in the code. Any ideas?


Code--

font_add_google("Roboto Condensed")
showtext_auto()

theme_custom = theme(
  text = element_text(family = "Roboto Condensed", size = 16),
  plot.title = element_text(
    face = 'bold',
    # colour = thematic::okabe_ito(8)[6],
    color = "dark blue",
    margin = margin (t=2, r=0, b = 5, l = 0, unit = "mm")
  ),
)
theme_set(theme_bw() + theme_custom)


p5 = cleaned.data %>%
  filter(!ambulance_eta_to_ambulance_arrival == 0) %>%
  filter(!dispatch_hour == 0) %>%
  filter(!eta_hour == 0) %>%
  filter(arrival_dep=="FMLH ED") %>%
  ggplot(aes(x = ambulance_name, y = ambulance_eta_to_ambulance_arrival, fill = ambulance_name)) +
  geom_boxplot() +
  labs (
    x="",
    y="minutes",
    title = "ETA vs. Actual arrival by EMS Agency - FMLH ED",
    subtitle = subtitle,
    caption = "time < 0 means ambo arrived earlier than the ETA; time > 0 means ambo arrived later than ETA"
  ) +
  scale_y_continuous(expand = c(0, 0), limits = c(-60, 60)) +
  theme(legend.position = "NONE")
 
 
 ggsave("fmlh eta vs actual.png", plot = p5, dpi = "retina", width = 16, units = "in")



before.png

after.png

Oliver Lee

unread,
Aug 15, 2022, 8:24:03 AM8/15/22
to ggplot2
I experienced the same issue.
What I did is to take screenshot in rstudio and then include the screenshot in rmarkdown as image.

Reply all
Reply to author
Forward
0 new messages