Set system font in R package Cairo in Mac OS X

江枫思渺然 提交于 2019-12-07 16:10:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!