4

I'm trying to use different fontfaces for a plot, I'm using showtext to load the font.

Working code goes:

library("tidyverse")
library("showtext")

font_add(family = "nutmeg", regular = "/nutmeg/Nutmeg-Regular.ttf", 
         bold = "/nutmeg/Nutmeg-Bold.ttf")
showtext.auto()

However, when trying to add, for example, a light fontface:

library("tidyverse")
library("showtext")

font_add(family = "nutmeg", regular = "/nutmeg/Nutmeg-Regular.ttf", 
         bold = "/nutmeg/Nutmeg-Bold.ttf", light = "/nutmeg/Nutmeg-Light.ttf")
showtext.auto()

I get the error: Error in font_add(family = "nutmeg", regular = "/nutmeg/Nutmeg-Regular.ttf", : unused argument (light = "/nutmeg/Nutmeg-Light.ttf")

I'm guessing showtext doesn't support fontfaces other than Regular, Bold and Italic. Is there a way to work around this? Please try to dumb it down, I'm really new at using R. Thanks!

Phil
  • 7,287
  • 3
  • 36
  • 66
e_terr
  • 43
  • 6
  • Hi Emma. You could only specify a font for regular (or plain), bold, italic and bold-italic (see `?font_add`. Also, I might be wrong but TBMK these are the only font faces supported by e.g. ggplot2 (see https://ggplot2.tidyverse.org/articles/ggplot2-specs.html#text). One option would be to assign the light font to one of the supported font faces e.g. bold-italic. Second option would be to register a second family, e.g. "nutlight" where you set the light font as the regular one. To me the second option looks like the cleaner approach. – stefan Apr 14 '22 at 18:29
  • 1
    Thanks Stefan! I tried the second option and it worked. – e_terr Apr 14 '22 at 18:34

0 Answers0