Using custom OTF fonts in ggplot2

I need to use my own font, namely "Archer", with ggplot2 in R. Archer is the otf font installed on my system (Mac OSX Yosemite).

This script (here: Changing fonts in ggplot2 ) does not work for Archer, but works fine with other fonts like Arial.

install.packages("extrafont");library(extrafont) font_import("Archer") library(ggplot2) qplot(1:10)+theme(text=element_text(family="Archer")) 

Is there something wrong with otf fonts?

+9
fonts r typeface ggplot2 macos
source share
2 answers

You will need to convert Archer from OTF to TTF. From extrafont github readme :

It currently allows the use of TrueType fonts with R

I am surprised. I had to do this because my organization also uses Archer. The first hit for this search is purple, so it’s possible that I used and it worked fine.

If you are having problems with extrafont also useful to check the available options with fonts() . Then you can check the import success.

If you save your graphic in a PDF file, make sure that you also insert fonts using grDevices::embedFonts or extrafont::embed_fonts .

+11
source share

You can try the showtext package, which works directly with OTF fonts.

 library(showtext) font.add("Archer", "Archer.otf") showtext.auto() library(ggplot2) qplot(1:10)+theme(text=element_text(family="Archer")) 

Please replace "Archer.otf" with the real name of the Archer font file on the system.

Using showtext does not require font attachment.

+14
source share

All Articles