我需要在R中的ggplot2中使用自定义字体,即“ Archer”。Archer是在我的系统上安装的otf字体(Mac OSX Yosemite)。
此脚本(在此处找到:Modifying fonts in ggplot2)不适用于Archer,但可以与Arial等其他字体一起使用。
install.packages("extrafont");library(extrafont)
font_import("Archer")
library(ggplot2)
qplot(1:10)+theme(text=element_text(family="Archer"))
特别是otf字体有问题吗?
[您需要将Archer从OTF转换为TTF。从extrafont
的github readme:
目前,它允许将TrueType字体与R一起使用
我很开心---我必须这样做,因为我的组织也使用Archer。 this search的第一击是紫色,所以大概是我用的,效果还不错。
extrafont
遇到问题时,用fonts()
检查可用选项也很有用。然后,您可以验证导入是否成功。
如果将绘图保存为PDF,请确保也使用grDevices::embedFonts
或extrafont::embed_fonts
嵌入字体。
您可以尝试直接在OTF字体上使用的showtext程序包。
library(showtext)
font.add("Archer", "Archer.otf")
showtext.auto()
library(ggplot2)
qplot(1:10)+theme(text=element_text(family="Archer"))
请在系统中用您的Archer字体的真实文件名替换“ Archer.otf”。
使用showtext
不需要嵌入字体。