在Ggplot2中使用自定义OTF字体

时间:2015-05-05 16:10:11

标签: r macos fonts ggplot2 typeface

我需要使用自定义字体,即“Archer”,在R中使用ggplot2。Archer是我系统上安装的otf字体(Mac OSX Yosemite)。

此脚本(在此处找到:Modifying fonts in ggplot2)不适用于Archer,但适用于其他字体,例如Arial。

@Override
public int getCount() {
  return NumbOfTabs;
}
}

特别是otf字体有问题吗?

2 个答案:

答案 0 :(得分:11)

您可以尝试使用直接适用于OTF字体的showtext包。

library(showtext)
font.add("Archer", "Archer.otf")
showtext.auto()
library(ggplot2)
qplot(1:10)+theme(text=element_text(family="Archer"))

请更换" Archer.otf"通过系统中Archer字体的真实文件名

使用showtext不需要嵌入字体。

答案 1 :(得分:9)

您需要将Archer从OTF转换为TTF。来自extrafont' s github readme

  

目前,它允许使用带有R

的TrueType字体

我很开心 - 我必须这样做,因为我的组织也使用Archer。 this search的第一个打击是紫色,所以可能是我使用过的,它运作得很好。

如果遇到fonts()问题,使用grDevices::embedFonts检查可用选项也很有用。然后,您可以验证导入是否成功。

如果您将地图保存为PDF,请确保使用extrafont::embed_fonts或{{1}}来嵌入字体。