在 Mac OS X 中使用 R 包 Cairo 设置系统字体

3

由于在使用Unicode在R的expression()命令内引发的问题,我正在切换到Mac OS X上的R来创建一些图形。然而,使用CairoPDF()时,我在Windows中用于选择字体的命令在Mac OS X上没有任何效果,输出的.pdf文件总是使用Helvetica字体。

library(package = "Cairo")
CairoPDF("test.pdf")
plot.new()
text(x=.5,y=.5,labels="\u0260",family="Times New Roman")
dev.off()

在Windows系统中的输出为:

enter image description here

在Mac OS X系统中的输出为:

enter image description here

Times New Roman字体在两个系统上完全相同。
1个回答

3
我用CairoFonts而不是family参数来实现,似乎family参数被忽略了。
> 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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接