31

What graphics devices let me use system fonts for text within charts? The base graphics system only has a small amount of documentation around the par(family=...) options.

Ideally I'd like to be able to use any font I can browse through a tool like xfontsel on Linux or the equivalent utilities on other platforms.

My current solution is to plot out as PDF and then use a 3rd party program to replace the fonts from within the PDF. This is not ideal.

Josh Reich
  • 6,477
  • 5
  • 28
  • 26

2 Answers2

53

A list of fonts is available to the pdf() command, like this:

> names(pdfFonts())
 [1] "serif"                "sans"                 "mono"                
 [4] "AvantGarde"           "Bookman"              "Courier"             
 [7] "Helvetica"            "Helvetica-Narrow"     "NewCenturySchoolbook"
[10] "Palatino"             "Times"                "URWGothic"           
... etc ...

To use when creating a PDF, for example:

> pdf(file="plot.pdf",family="Palatino", pointsize=16, width=16,height=10)
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
ariddell
  • 3,413
  • 34
  • 32
9

You can use system fonts with cairo_pdf. On Ubuntu (and many other types of Linux, I guess), the family argument takes any font name you see in fc-list.

Alternatively, you can use the extrafont package. This will allow you to use any system font with the regular pdf device.

Mihai Capotă
  • 2,271
  • 2
  • 32
  • 24