EPS figures using the Arial typeface, with R and Ghostscript

I usually use the default font in R and export my figures in pdf. Unfortunately, some journals want figures in the EPS format, and do not accept Helvetica (default font in R). Gavin Simpson has an excellent, extremely useful and detailed post on the issue; my post recycles a lot of theirĀ tricks.

Use Arial in the figures generated by R

You first need to download and install the extrafont package.


If it is the first time that you are using the package, you need to install the fonts… and this takes forever. Luckily, you can also choose to only install Arial fonts, and the process is much faster.


If you want to be able to use all the fonts of your system (say if you want to use Comic sans in your R figures), remove the pattern argument:


but be prepared to wait for a while.

I could not find a way to generate decent eps files directly from R, so I first saved my figures as pdfs. To use Arial in your figures, you just need to change the family argument when calling pdf:

pdf("file.pdf", family="Arial")
 # your code for plotting

We are not done yet: the fonts now have to be embedded in the pdf:


You can specify the name of an outfile if you do not want to overwrite the previous pdf.

Note that this step requires Ghostscript, that may not be installed on your machine (it was not on mine)…

Installing Ghoscript on a Mac

(and realizing that sometimes life was easier with Ubuntu). This was quite a painful process, until I discovered Homebrew, “the missing package manager for OS X”.

First, you need to install Homebrew (instruction taken from the Homebrew homepage):

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

and then type (as explained there):

brew install ghostscript

Congratulations, now Ghostscript is installed on your machine (make sure you embed the fonts again in R with the embed_fonts() function).

Convert .pdf files to .eps

Last step: convert these .pdf figures in the eps format. Let’s say that you have generated a bunch of figures with R, stored them in the same folder, and want to convert them all. Open a terminal, go to the folder containing your figures

cd ~/path/to/your/folder

and then type the following two lines. The first line does the pdf -> ps conversion, and the second ps->eps (for some reason, it’s not possible to go directly from pdf to eps.)

for f in *.pdf; do pdf2ps $f; done
for f in *.ps; do ps2eps $f; done

And that’s it! You should now find in your folder all your figures converted to the EPS format.