Set system font in R package Cairo in Mac OS X

2019-05-15 02:03发布

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:

enter image description here

The output in Mac OS X is:

enter image description here

The Times New Roman font is exactly the same on both systems.

1条回答
Explosion°爆炸
2楼-- · 2019-05-15 02:40

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 

enter image description here

> 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 

enter image description here

查看更多
登录 后发表回答