Problem using theme font in ggplot

Hi. I am trying to create a chart in ggplot and using the hrbrthemes package. The latter package includes a number of fonts and I want to use one of them, Goldman Sans. In the script I include them in

geom_text( data = xdf, aes(party, votes + 0.015, label = scales::percent(votes, 0.1)), position = position_nudge(0.125), family = font_gs, size = 3, color = "black", fontface = "bold" )

but the result is a graph with only bars and no text and the console warns me that

Warning messages: 1: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) : no font could be found for family "Goldman Sans Condensed"

and so on up to fifty warnings. But the font is installed at /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/hrbrthemes/fonts/goldman-sans

What could be the problem?

1 Like

I'm not sure that downloading R packages that nominally give you access to a font will actually make the font available on your system. You may need to download and install the font independently, and then try running your code again.

The issue is likely that R and ggplot2 do not automatically register the fonts from hrbrthemes. Try explicitly registering them using the extrafont or systemfonts package.

  1. Load the fonts:

    library(hrbrthemes)
    hrbrthemes::import_roboto_condensed()  # Also imports Goldman Sans
    
  2. If the issue persists, try registering the fonts manually:

    library(systemfonts)
    register_font(name = "Goldman Sans", plain = "/path/to/Goldman-Sans-Regular.ttf")
    
  3. Ensure your R session recognizes the font:

    systemfonts::match_font("Goldman Sans")
    

If none of this works, try using showtext for better font handling.