gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:02:25 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com