extrafonts-package:将图另存为pdf且缺少文本的问题

吉林0709

extrafonts-package在R中使用导入字体'roboto condensed'并将其用于我的绘图。只要我仅在RStudio中生成图,它就可以工作,但是如果我想将图导出为pdf,它将失败。我收到许多警告,例如font width unknown for character 0x41,但R仍会生成pdf,但没有任何文本。我也尝试嵌入字体,但是如果我调用embed_fonts(),则什么也不会发生,并且R会卡在函数调用中,直到我将其转义为止。

library(extrafont)
font_import(pattern = "Roboto")

# creates plot in R with correct font
loadfonts(device = "win")
par(mar = c(0, 0, 0, 0), pin = c(4, 1), xpd = TRUE, family = "Roboto Condensed")

plot(1, type = "n", xlim = c(.5, 5.5), ylim = c(0, 1), xaxt = "n", yaxt = "n", xlab = "", ylab = "")
abline(v = 1:5, xpd = FALSE, col = "grey")
text(x = 1:5, y = .5, labels = LETTERS[1:5])


# creates plot and tries to export it as a pdf - fails
loadfonts(device = "pdf")
pdf(file = "test.pdf", family = "Roboto Condensed")

par(mar = c(0, 0, 0, 0), pin = c(4, 1), xpd = TRUE, family = "Roboto Condensed")
plot(1, type = "n", xlim = c(.5, 5.5), ylim = c(0, 1), xaxt = "n", yaxt = "n", xlab = "", ylab = "")
abline(v = 1:5, xpd = FALSE, col = "grey")
text(x = 1:5, y = .5, labels = LETTERS[1:5])

dev.off()

# embedding the font into the pdf forces me to escape the function call, because nothing happens
Sys.setenv(R_GSCMD = "D:/Programme/gs/gs9.02/bin/gswin64.exe")
embedFonts("test.pdf")

在此处输入图片说明

哈劳

对我来说,它可以cairo_pdf代替使用pdf尝试:

cairo_pdf(file = "test.pdf", family = "Roboto Condensed")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章