Skip to content
R for the Rest of Us Logo

Customize Your Fonts

This lesson is locked

Get access to all lessons in this course.

If the video is not playing correctly, you can watch it in a new window

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Heads up! Working with custom fonts changed significantly after I recorded the lessons for this course. I've added an updated video below. The new changes make working with custom fonts much easier than it used to be.

Your Turn

  1. Install the ragg and systemfonts package

  2. Change your settings in RStudio so you can render with AGG

  3. Change all text in your last plot to use a custom font (you’ll have to do this in a few different places)

  4. Save your plot using ggsave()

Learn More

If you’re interested in a quite technical blog post on the changes to working with custom fonts, Thomas Lin Pedersen, developer of ragg and systemfonts, has written up an explanation of the problem these packages solve.

The best resource for learning more about how to use custom fonts is this article by June Choe.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Abby Isaacson

Abby Isaacson

May 19, 2021

Just curious if the fonts library changes over time? For example, your Karla font isn't an option among the 158 font choices that show up for me.

Harold Stanislaw

Harold Stanislaw

May 26, 2021

This may be peculiar to my setup, but when I run the fonts command I see only 150 fonts, even though my system actually has quite a few more. (Perhaps they're not showing up because when I ran loadfonts I got this error message LOTS of times: "string 4 is invalid in this localeinput".) I tried using Bauhaus 93, which was not listed by the fonts command, and Bauhaus was actually applied to my graph. So, fonts are available to R that don't show up when running the fonts command.

Lucilla Piccari

Lucilla Piccari

May 26, 2021

Hello!

When I try to import "Karla" with the following code: font_import(pattern = "Karla") I get the following error message: Scanning ttf files in C:\Windows\Fonts ... Extracting .afm files from .ttf files... Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : arguments imply differing number of rows: 0, 1

I have already imported other fonts and have verified that 187 are available, but Karla is not among them.

Am I doing something wrong?

Thank you!

I've tried three things and only Heiss' advice to specifically load Comic Sans works (which is not super helpful since i'll never use that font). I'm on Windows.

  1. I installed extrafont. When I run font_import() I get the following in the Console: > font_import() Importing fonts may take a few minutes, depending on the number of fonts and the speed of the system. Continue? [y/n] y Scanning ttf files in C:\windows\Fonts ... Extracting .afm files from .ttf files... C:\Windows\Fonts\AGENCYB.TTF : No FontName. Skipping. C:\Windows\Fonts\AGENCYR.TTF : No FontName. Skipping. C:\Windows\Fonts\ALGER.TTF : No FontName. Skipping. C:\Windows\Fonts\ANTQUAB.TTF : No FontName. Skipping. .... C:\Windows\Fonts\WINGDNG3.TTF : No FontName. Skipping. C:\Windows\Fonts\ZWAdobeF.TTF : No FontName. Skipping. Found FontName for 0 fonts. Scanning afm files in C:/Users/mmakel1/OneDrive - Johns Hopkins/Documents/R/win-library/4.1/extrafontdb/metrics There were 50 or more warnings (use warnings() to see the first 50)"

  2. When I run windowsFonts() > windowsFonts() $serif [1] "TT Times New Roman" $sans [1] "TT Arial" $mono [1] "TT Courier New" >

  3. following Andrew Heiss' blog, when i run capabilities(), I do get TRUE for Cairo, but don't see it in my list of fonts.

  4. When I run, [from Heiss blog] windowsFonts(Comic Sans MS = windowsFont("Comic Sans MS") That increases my fonts to 4. (but not super helpful since I will never use Comic Sans). It's fine if I have to load them one at a time, but I don't know the official font names in Windows. ...The above errors aren't as the closest to Comic Sans MS are: C:\Windows\Fonts\comic.ttf : No FontName. Skipping. C:\Windows\Fonts\comicbd.ttf : No FontName. Skipping. C:\Windows\Fonts\comici.ttf : No FontName. Skipping.

JULIO VERA DE LEON

JULIO VERA DE LEON

May 7, 2022

I couldn't make it work. I installed the package, ran font import (I get a No Font Name error) and then with fonts I get a "NULL".

Mychal Davis

Mychal Davis

June 2, 2022

Hello,

I am not able to load any fonts into R. I am using Windows. I tried using the code that was submitted below "library(extrafont) library(remotes) remotes::install_version(“Rttf2pt1”, version = “1.3.8”) extrafont::font_import()", but that did not work for me.

Also, I'm not certain that I am loading the fonts correctly in showtext. When I followed the directions listed on https://cran.rstudio.com/web/packages/showtext/vignettes/introduction.html, I got the following error: > showtext::font_add_google Error: 'font_add_google' is not an exported object from 'namespace:showtext'

Hannah Ridenour LaFrance

Hannah Ridenour LaFrance

December 3, 2022

I'm getting an unused argument error on (base_family = "Ariel"), regardless of what font family I try. I had no problem viewing my list of available fonts, but none of them want to work with theme_minimal.