[R] Mac OSX fonts in R plots

Fernando Diaz fernandodiaz0 at gmail.com
Thu Aug 9 16:32:26 CEST 2007


I had been looking for information about including OSX fonts in R
plots for a long time and never quite found the answer.  I spent an
hour or so gathering together the following solution which, as far as
I have tested, works.  I'm posting this for feedback and and
archiving.  I'd be interested in any caveats about the brittleness of
the technique.

Thanks.

F

-----

1. Find font
	system font path: /Library/Fonts/
2. Extract ttf (if necessary) with fondu [http://fondu.sourceforge.net/]
	eg, fondu -force Optima.dfont
3. ttf2asm for each ttf file, stripping the Copyright and warning
3. copy files to
	RHOME/library/grDevices/afm
	(usually,
	/Library/Frameworks/R.framework/Versions/2.5/Resources/library/grDevices/afm
	)
4. R code to use the font; eg,
	newfont= Type1Font("Optima",c("OptimaRegular.afm","OptimaBold.afm","OptimaItalic.afm","OptimaBoldItalic.afm"))
	pdf("newfont.pdf",version = "1.4",family=newfont)
	plot(rnorm,col="red")
	dev.off()



More information about the R-help mailing list