0

I'm following the example here but it doesn't work. How can I change to "EB Garamont 12" font?

library(showtext)
library(ggplot2)
font_files()
windows()
font_add_google("EB Garamond")
font_families()
a <- ggplot(mtcars, aes(x = wt, y = mpg)) + 
  geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme_set(theme_gray(base_size = 20, base_family = "EB Garamond" )) +
  annotate("text", 1, 11, label = 'GGTT', hjust = 0,
           family = myFont2, size = 10) 
print(a) 

enter image description here

I also did this using font_import(paths = NULL, recursive = TRUE, prompt = TRUE,pattern = NULL) but nowhere do I see the EB Garamond family.

enter image description here

font_import(paths = NULL, recursive = TRUE, prompt = TRUE,pattern = NULL)

#Scanning ttf files in C:\WINDOWS\Fonts ...
#Extracting .afm files from .ttf files...
#C:\Windows\Fonts\arial.ttf : ArialMT already registered in fonts database. Skipping.
#...
#...
#C:\Windows\Fonts\ebrima.ttf : Ebrima already registered in fonts database. Skipping.
#C:\Windows\Fonts\ebrimabd.ttf : Ebrima-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\euclid.ttf : Euclid already registered in fonts database. Skipping.
#C:\Windows\Fonts\euclidb.ttf : Euclid-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\euclidbi.ttf : Euclid-BoldItalic already registered in fonts database. Skipping.
#C:\Windows\Fonts\euclidi.ttf : Euclid-Italic already registered in fonts database. Skipping.
#C:\Windows\Fonts\eucsym.ttf : EuclidSymbol already registered in fonts database. Skipping.
#C:\Windows\Fonts\eucsymb.ttf : EuclidSymbol-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\eucsymbi.ttf : EuclidSymbol-BoldItalic already registered in fonts database. Skipping.
#C:\Windows\Fonts\eucsymi.ttf : EuclidSymbol-Italic already registered in fonts database. Skipping.
#C:\Windows\Fonts\euextra.ttf : EuclidExtra already registered in fonts database. Skipping.
#C:\Windows\Fonts\euextrab.ttf : EuclidExtra-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\eufrak.ttf : EuclidFraktur already registered in fonts database. Skipping.
#C:\Windows\Fonts\eufrakb.ttf : EuclidFraktur-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\eumat1.ttf : EuclidMathOne already registered in fonts database. Skipping.
#C:\Windows\Fonts\eumat1b.ttf : EuclidMathOne-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\eumat2.ttf : EuclidMathTwo already registered in fonts database. Skipping.
#C:\Windows\Fonts\eumat2b.ttf : EuclidMathTwo-Bold already registered in fonts database. Skipping.
#C:\Windows\Fonts\fences.ttf : Fences-Plain already registered in fonts database. Skipping.
#C:\Windows\Fonts\framd.ttf : FranklinGothic-Medium already registered in fonts database. Skipping.
#...

extrafont::loadfonts(device="win") #I can't find EB Garamond
cdcarrion
  • 574
  • 6
  • 22

1 Answers1

1

You need to include showtext_auto() before plotting.

library(showtext)
library(ggplot2)

font_add_google("EB Garamond")
windows()

showtext_auto()

ggplot(mtcars, aes(x = wt, y = mpg)) + 
  geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme_set(theme_gray(base_size = 20, base_family = "EB Garamond" )) +
  annotate("text", 1, 11, label = 'GGTT', hjust = 0,
           family = "EB Garamond", size = 10) 

The windows device now shows:

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • I didn't realize that function, thx. And how could I load the font `EB Garamond 12 ALL SC` from my computer (the one in the image)?. – cdcarrion Aug 26 '20 at 15:08
  • Hi, I am trying to follow this answer but when I run windows(), I get Error in windows() : could not find function "windows", what is the package that needs to be installed for this function? I am using R studio in a Mac. – Daniela Rodrigues Nov 19 '22 at 16:36