在Mac OS X中的R包Cairo中设置系统字体 [英] Set system font in R package Cairo in Mac OS X
问题描述
由于在R的expression()命令中使用Unicode 引起的问题,我切换到Mac OS X上的R以创建一些图.但是,使用CairoPDF()
,我在Windows中使用的选择字体的命令对Mac OS X无效,在Mac OS X上,输出.pdf
文件始终使用Helvetica字体.
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()
Windows中的输出为:
The output in Windows is:
Mac OS X中的输出为:
The output in Mac OS X is:
Times New Roman字体在两个系统上完全相同.
The Times New Roman font is exactly the same on both systems.
推荐答案
我是用CairoFonts而不是家庭论证来做到这一点的,这似乎被忽略了.
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
这篇关于在Mac OS X中的R包Cairo中设置系统字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!