问题描述
我需要在R中使用带有ggplot2的自定义字体,即"Archer".Archer是我的系统(Mac OSX Yosemite)上安装的otf字体.
I need to use a custom font, namely "Archer", with ggplot2 in R. Archer is an otf typeface installed on my system (Mac OSX Yosemite).
此脚本(在此处找到:修改ggplot2中的字体)不适用于Archer ,但可以与Arial等其他字体配合使用.
This script (found here: Modifying fonts in ggplot2) doesn't work for Archer, but works fine with other fonts such as Arial.
install.packages("extrafont");library(extrafont)
font_import("Archer")
library(ggplot2)
qplot(1:10)+theme(text=element_text(family="Archer"))
特别是otf字体有问题吗?
Is there something wrong with otf typefaces in particular?
推荐答案
您需要将Archer从OTF转换为TTF.从extrafont
的 github自述文件:
You'll need to convert Archer from an OTF to a TTF. From extrafont
's github readme:
我很开心--我必须这样做,因为我的组织也使用Archer. 是紫色的,所以大概是我使用的,并且效果很好.
I'm amused---I had to do this because my organization also uses Archer. The first hit for this search is purple, so probably that's what I used and it worked just fine.
当遇到extrafont
问题时,使用fonts()
检查可用选项也很有用.然后,您可以验证导入是否成功.
When having trouble with extrafont
it can also be useful to check the available options with fonts()
. Then you can verify that your import was successful.
如果将图形保存为PDF,请确保也使用grDevices::embedFonts
或extrafont::embed_fonts
嵌入字体.
If you save your plot to a PDF, to make sure to embed the fonts as well, using grDevices::embedFonts
or extrafont::embed_fonts
.
这篇关于在ggplot2中使用自定义OTF字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!