0

I downloaded the latest RStudio the other day and I've started running into problems with the font when I use ggsave().

I specify the font as I always have (after loading fonts with extrafont, and it shows up correctly in the RStudio viewer), but when I save the output through ggsave() it appears to give me a different style of that font family (Myriad Pro). This didn't happen before downloading the latest RStudio.

Here's a example:

library(tidyverse)
extrafont::loadfonts(device = "win")

n <- 6
dat <- data.frame(id=1:n, 
                  date=seq.Date(as.Date("2020-12-26"), as.Date("2020-12-31"), "day"),
                  group=rep(LETTERS[1:2], n/2),
                  age=sample(18:30, n, replace=TRUE),
                  type=factor(paste("type", 1:n)),
                  x=rnorm(n))

dat %>%
  ggplot(aes(age, x)) +
  labs(x = "Here is a label for my x axis",
       y = "Here is a slightly different one for my y axis",
       title = "This is an example title") +
  theme(text = element_text(family = "Myriad Pro"))

ggsave("test_output.png")  

In RStudio, I'm seeing this (font is correct):

rstudio_viewer

but ggsave() is giving me this (font is incorrect) and I have no idea why:

ggsave_output

I'm using the same code that's worked previously, but it seems like I'm now getting the condensed style of Myriad Pro?

Does anyone have any ideas about what might be happening?

Thanks!

Phil
  • 7,287
  • 3
  • 36
  • 66
PupHendo
  • 145
  • 1
  • 8
  • I'll also add that when I use gtsave() to save my {gt} tables, the font works fine? – PupHendo Oct 08 '21 at 06:37
  • What version of R, RStudio, and extrafont are you using? – MrFlick Oct 08 '21 at 06:38
  • If anyone comes to this with the same issue, it seems that the `ragg` package (and associated graphics device) was causing the unexpected font behaviour. Uninstalling {ragg} by using `installr::uninstall.packages("ragg")` worked for me. I'm not sure why it worked, or why `ragg` doesn't give me the font I'm after. I've since read about the many advantages of the `ragg` graphics device, so I might keep experimenting to try and find a way to get my desired output with `ragg`. I'm interested to hear if anyone thinks they know why it might be happening? – PupHendo Oct 10 '21 at 04:10

0 Answers0