Kategorien
Allgemein

Using Opentype (OTF) with R

R is a great tool to analyze data and build beautiful graphs. However, not ever problem has a straight forward solution. One of those problems is using OpenType fonts in graphs.

After some despair, I found this great How-To: How to use your favorite fonts in R charts. Because it explains a little more than necessary for this problem, here is my final walk-through:

Step 0:

Download Rtools. Be careful to select the correct version for your installation of R. I use R 3.1.2 and Rtools31.

Step 1:

Install the necessary packages:

library(devtools)
install_github("Rttf2pt1", "wch")
install_github("extrafont", "wch")
install_github("Rttf2pt1", "wch", "freetype") 
install_github("Rttf2pt1", "wch", "freetype2") 

Step 3:

Load the fonts:

library(extrafont)
font_import()

Look up the name of the font in the results of

fonts()

If everything worked, now you are ready to use the font for your plots:

png(filename = "out.png", width=7, height=5, units = "in", pointsize = 8, res=300, restoreConsole = TRUE, type = "cairo-png", , family="Myriad Pro light")

Photo by Het Nieuwe Instituut – Architecture Collection