Mar 242010
Motivated by the excellent R package pgfSweave, I begin to notice the font families in my graphs when writing Sweave documents. The default font family for PDF graphs is Helvetica, which is, in most cases (I think), inconsistent with the LaTeX font styles. Some common font families are listed in ?postscript, and we can take a look at them by:

for (f in c("AvantGarde", "Bookman", "Courier", "Helvetica",
    "Helvetica-Narrow", "NewCenturySchoolbook", "Palatino", "Times")) {
    pdf.options(family = f)
    pdf(paste(f, ".pdf", sep = ""))
    set.seed(123)
    plot(rnorm(25), pch = 1:25, xlab = "xlab family", ylab = "ylab font",
        main = paste("Font Families in R (PDF):", f))
    text(13, 0, "Text in the Middle")
    mtext(sprintf("pdf.options(family = \"%s\")", f), side = 4)
    dev.off()
}

Here is a merged PDF containing the above single PDF files:

R-PDF-font-families.pdf (29K)

It seems that "Bookman", "NewCenturySchoolbook", "Palatino" and "Times" can be better choices when using Sweave because they are serif fonts, which are usually more consistent with LaTeX PDF.

Related Posts

6 Responses to “Font Families for the R PDF Device”

Comments (6)
  1. Paul says:

    Not only are these more consistent with Computer Modern, but most do exist as distinguished LaTeX fonts. Bookman as “bookman”, New Century Schoolbook as “fouriernc”, Palatino as “mathpazo”, and Times as “mathptmx”.

  2. Frederik Hjorth says:

    Excellent tip. On a related note, is it possible to produce regular R graphs using the same font as in LaTeX pdf’s (Computer Modern I believe it’s called) for inserting manually into LaTeX documents?

    Best,
    Fred

  3. mjm says:

    how about real os font access like xetex? Anyone figure out how to make Quartz or Cairo graphics devices (both of which are better than the antiquated postscript grdev) use system fonts?

    • Yihui Xie says:

      I guess the help page ?embedFonts can be useful and see the reference therein:

      Paul Murrell and Brian Ripley (2006) Non-standard fonts in PostScript and PDF graphics. R News, 6(2):41–47. http://cran.r-project.org/doc/Rnews/Rnews_2006-2.pdf.

      Or you may take a look at the pgfSweave package too. Since it records R graphics as LaTeX documents (like pictex but more advanced), you can certainly use XeTeX to compile your LaTeX document.

Leave a Reply

(required)

(required)

WWW.YIHUI.NAME XIE@YIHUI.NAME © 2007 - 2010 by Yihui Xie