【问题标题】:pdf with extrafont creates overlapping text带有额外字体的 pdf 创建重叠文本
【发布时间】:2015-10-02 10:09:05
【问题描述】:

我正在尝试在我的 pdf 中使用 Arial 字体,但是当我按照 extrafont 帮助文件中的说明进行操作时,每个点的文本都会相互覆盖:

library(extrafont)
library(ggplot2)

my_pdf <- function(file, width, height){
  loadfonts()
  pdf(file = file, width = width, height = height,
      family = "Arial")
} 

my_pdf("ArialTester.pdf")
qplot(1:10, 1:10, "point") + ggtitle(paste0(LETTERS,letters, collapse=""))
dev.off()

我在 pdf 中得到以下内容。请注意,标题是字母表。

这个问题的上下文是knitr,所以我需要一个可以设置为块选项的设备函数(即dev = 'my_pdf'

我做错了什么?

【问题讨论】:

    标签: r pdf fonts ggplot2 knitr


    【解决方案1】:

    您需要使用embed_fonts()

    library(extrafont)
    library(ggplot2)
    
    my_pdf <- function(file, width, height){
      loadfonts()
      pdf(file = file, width = width, height = height,
          family = "Arial")
    }
    
    my_pdf("ArialTester.pdf")
    g <- qplot(1:10, 1:10, "point") + ggtitle(paste0(LETTERS,letters, collapse="")) +
      theme(text = element_text(family = "Arial"))
    plot(g)
    dev.off()
    embed_fonts("ArialTester.pdf")
    

    【讨论】:

    • 我需要一个my_pdf 类型的函数,因为我希望它能够处理knitr 中的输出。
    • 休,我编辑了我的答案以保留该功能。我认为您需要做的就是添加embed_fonts() 步骤。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 2014-05-21
    • 2011-12-14
    • 1970-01-01
    相关资源
    最近更新 更多