0

I'm trying to move away from the extrafont package due to these issues. This is a bit of a shame as apart from that this package works great; but alas it seems that showtext is the best alternative.

But I'm struggling a bit as the documentation of the package is very short.

I have added one of my custom fonts (actually it's about 15) using:

library(showtext)
font_add(family = "Myriad Pro",regular = "C:/USER/Downloads/Myriad Pro Regular.ttf")
showtext_auto()

And then I would suspect that in every new script (once I've installed the font) I would only need something like this:

library(showtext)
showtext_auto()

library(ggplot2)
ggplot(mtcars, aes(y = hp, x = mpg)) + geom_line() + theme(text = element_text(family = "Myriad Pro"))

But then it always gives me about 50 warnings:

...
48: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font family 'Myriad Pro' not found, will use 'sans' instead
49: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font family 'Myriad Pro' not found, will use 'sans' instead
50: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font family 'Myriad Pro' not found, will use 'sans' instead

Am I doing something wrong? Surely it can't be that I need to import the font every single time I start a new script, right?

Thanks for your help!

p.s. font used here available from here.

Moritz Schwarz
  • 2,019
  • 2
  • 15
  • 33
  • This appears to be an inbuilt behaviour of `showtext`- if you [run the example from their Github page](https://github.com/yixuan/showtext#a-quick-example), on reload none of the fonts are there. Unless there is a way of saving them to the environment, I think they just go away on reload – Mark Jun 28 '23 at 23:05
  • 1
    Yes, this code loads the fonts into your R session. When you restart/end the R session, they are no longer loaded. To avoid copy pasting, what I've previously done is created a personal R package that runs this code on loading so you can run e.g. `library(PersonalFontPackage)` and the fonts will be loaded in one line. – nrennie Jun 28 '23 at 23:08
  • one option is using `extrafont::font_import()` – Mark Jun 28 '23 at 23:36

0 Answers0