r - 额外字体包 : problems saving plot as pdf with missing text

标签 r fonts

我正在使用 extrafonts-package在 R 中导入字体“roboto condensed”并将其用于我的情节。只要我只在 RStudio 中生成绘图,它就可以工作,但如果我想将绘图导出为 pdf,它就会失败。我收到许多警告,例如 font width unknown for character 0x41 ,但 R 仍然生成一个 pdf,但没有任何文本。我也尝试嵌入字体,但是如果我调用 embed_fonts() 没有任何 react ,并且 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")

enter image description here

最佳答案

对我来说,使用 cairo_pdf 有效而不是 pdf .尝试:

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

关于r - 额外字体包 : problems saving plot as pdf with missing text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48908273/

相关文章:

silverlight - Silverlight 4中的字体列表

r - 数据表中的图标 Shiny

r - 如何从多个向量创建唯一的组合列表?

fonts - 向 jasper 报告添加字体

html - 如何让 SVG 中的字体显示在网页中?

java - 在未设置的 android 字体上使用 iText

r - 如何从R中的日期中提取月份

r - 如何从 Shiny 的callModule函数返回输入值

javascript - R 中的 MVC 模式

c# - C#中的FNT字体文件