A lot of things are great and easy to do in
ggplot2…but putting new fonts in can be a pain in the butt. I had to do this last week, so I decided to write down what I did (as much for me as for anyone else).
- Get the package
- Import system fonts to R (this can take a minute):
- Load fonts:
loadfonts(device = 'win'). If you’re on a Mac, just
- Fonts are loaded!
Now, when you type
windowsFonts() in windows or , you’ll get a list of all available fonts:
$serif  "TT Times New Roman" $sans  "TT Arial" $mono  "TT Courier New" $`Agency FB`  "Agency FB" $Algerian  "Algerian" $`Arial Black`  "Arial Black" $Arial  "Arial" ...
Now, when you want to use a font in
ggplot, it’s as easy as calling
theme(family = 'Arial').
Note that if you’re on a Mac, you won’t get the default Microsoft Office fonts, so if you’re trying to convince people that you can switch from Powerpoint by making Excel-like plot styles, you’ll need to add the fonts manually. Luckily, it’s really easy to do through the font book utility on your Mac (just type
Font into spotlight), and this blog post.