1

I'd like to use the fonts my organisation uses in ggplot. I have these in an .otf format on my computer. However, after several hours I have still made zero progress in actually using the fonts in plots.

I've tried using showtext/extrafont/sysfont and no luck.

When I call font_files() I do see the fonts (as they are installed on my PC), but when I try to set the familiy argument to the font I get the following errors:

Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
5: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
6: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database

Like I said the fonts are installed. I can use them in Word and other programs and can see them in the windows/fonts folder.

With showtext I've ran:

library(showtext)
showtext_auto() 
font_add("Test2", regular = "Font_Regular_2.otf", italic = "Font_Italic_2.otf")
font_families()

And I do see the "Test2" added to the font families, however when I try add it to my plot nothing changes:

theme(plot.title = element_text(color = "blue", size = 28, face = "bold", hjust = 0.5, family = "Test2"))

Afterwards, I've tried everything discussed in this topic but no results.

It'd be great if I can get a step by step explanation, since I'm really not sure where I'm going wrong here.

Initially I want to use export my plots as png, later I plan to export them in PDF for use in publications. I've read that the latter also requires an extra step?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Justin
  • 141
  • 8

1 Answers1

1

So a year later, I found a solution. The problem seems to have been related to the location of the font file for some reason. Loading it from the Windows/Fonts folder didn't work.

When I put it somewhere else in the My Documents-folder and gave showtext the path to the files there, it worked.

library(showtext)

showtext_auto() 

font_add("Test2", regular = "C:\\Users\\MYNAME\\Documents\\FOLDERNAME\\Testfont_2.otf")

font_families()
Justin
  • 141
  • 8