问题
Because of the issue raised in Using Unicode inside R's expression() command, I am switching to R on Mac OS X to create some plots. Using CairoPDF()
, however, the commands I use in Windows to select my fonts don't have any effect on Mac OS X, where the output .pdf
file always has the Helvetica font.
library(package = "Cairo")
CairoPDF("test.pdf")
plot.new()
text(x=.5,y=.5,labels="\u0260",family="Times New Roman")
dev.off()
The output in Windows is:

The output in Mac OS X is:

The Times New Roman font is exactly the same on both systems.
回答1:
I did it with CairoFonts rather than the family argument, which seems to be getting ignored.
> CairoPDF("test.pdf")
> plot.new()
> text(x=.5,y=.5,labels="\u0260",family="Times New Roman")
> dev.off()
quartz
2

> CairoFonts( # slight mod to example in ?CairoFonts page
+ regular="TimesNewRoman:style=Regular",
+ bold="FreeSans:style=Bold",
+ italic="FreeSans:style=Oblique",
+ bolditalic="FreeSans:style=BoldOblique"
+ )
>
> CairoPDF("test.pdf")
> plot.new()
> text(x=.5,y=.5, labels="\u0260" )
> dev.off()
quartz
2

来源:https://stackoverflow.com/questions/19890298/set-system-font-in-r-package-cairo-in-mac-os-x