【问题标题】:Using custom OTF fonts in ggplot2在 ggplot2 中使用自定义 OTF 字体
【发布时间】:2015-07-15 11:45:54
【问题描述】:

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

此脚本(可在此处找到: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 字体有什么问题吗?

【问题讨论】:

    标签: r macos fonts ggplot2 typeface


    【解决方案1】:

    您需要将 Archer 从 OTF 转换为 TTF。来自extrafontgithub readme

    目前它允许在 R 中使用 TrueType 字体

    我很开心 --- 我必须这样做,因为我的组织也使用 Archer。 this search 的第一次点击是紫色的,所以我可能就是用的,而且效果很好。

    extrafont 遇到问题时,使用fonts() 检查可用选项也很有用。然后您可以验证您的导入是否成功。

    如果您将绘图保存为 PDF,请确保也嵌入字体,使用 grDevices::embedFontsextrafont::embed_fonts

    【讨论】:

      【解决方案2】:

      您可以试试showtext 包,它直接适用于 OTF 字体。

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

      请将“Archer.otf”替换为系统中您的 Archer 字体的真实文件名

      使用showtext 不需要嵌入字体。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-05
        • 2019-09-14
        • 2016-11-29
        • 1970-01-01
        • 2010-11-25
        • 1970-01-01
        • 2015-06-27
        • 2015-08-10
        相关资源
        最近更新 更多