1

I am on Mac and need to use Calibri font for all ggplots, but i cannot make it work with either extrafont or showtext packages:

font_import(prompt = FALSE, pattern = "calibri")

returns

Scanning ttf files in /Library/Fonts/, /System/Library/Fonts, /System/Library/Fonts/Supplemental, ~/Library/Fonts/ ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 0, 1

and with showtext

list_of_fonts <- as.data.frame(font_files())

grep(pattern = "Calibri", x = list_of_fonts$family, ignore.case = TRUE, value = TRUE)

i get

character(0)

I use Calibri in Word with no issue, but how to get it to use with ggplot?

theme_set(theme_minimal(
  base_family="Calibri"
))


In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "Calibri"
m45ha
  • 399
  • 1
  • 9

1 Answers1

3

Option 1:

The issue seems like mentioned here that you need to downgrade the Rttf2pt1 package like this:

library(ggplot2)
library(showtext)
library(extrafont)
library(remotes)
remotes::install_version("Rttf2pt1", version = "1.3.8")
extrafont::font_import()

theme_set(theme_minimal(
  base_family="Calibri"
))
ggplot(data = mpg, aes(x = class)) +
  geom_bar(stat = "count")

Created on 2023-01-01 with reprex v2.0.2

Option 2:

Another option may be downloading the calibre.ttf file and placing it in your library fonts folder on Mac. You can check this using font_paths(). After that you can import it like this:

font_import(paths = "/Library/Fonts", pattern = "calibri.ttf")

You can use the following code to check if the font is on your machine:

list_of_fonts <- as.data.frame(font_files())
grep(pattern = "Calibri", x = list_of_fonts$family, ignore.case = TRUE, value = TRUE)

Please note: I am also using Mac.

Quinten
  • 35,235
  • 5
  • 20
  • 53