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:
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)
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”.
I didn’t know that… Thanks for telling me!
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
The first sentence of this post is exactly the answer. You may take a look at the R package
pgfSweave(read its vignette!) and I believe you will be thrilled to see that R graphs can be inserted into LaTeX as native LaTeX child documents. Also you can find a demo here: http://yihui.name/en/wp-content/uploads/2010/02/lyx-pgfsweave-demo.pdfhow 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?
I guess the help page
?embedFontscan 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
pgfSweavepackage too. Since it records R graphics as LaTeX documents (likepictexbut more advanced), you can certainly use XeTeX to compile your LaTeX document.