我目前正试图在我的所有情节中使用Arial.ttf.我在网上找到了几本关于字体的手册,但是当我尝试通过ggsave和默认设备保存底池时,我遇到了问题.
我正在运行以下最小的工作示例来重现此错误:
Sys.setenv(R_GSCMD="D:/gs/bin/gswin64c.exe")
library(ggplot2)
require(extrafont)
font_import(prompt = F, pattern = "arial.ttf")
font_import(prompt = F, pattern = "JOKERMAN.TTF")
loadfonts(device="win", quiet = T)
loadfonts(device="pdf", quiet = T)
plot <- ggplot(mtcars, aes(wt, mpg, colour = hp)) + geom_point()
jokerman_plot <- plot + theme_bw(base_family = "Jokerman")
arial_plot <- plot + theme_bw(base_family = "Arial")
ggsave("arial_plot.png", arial_plot)
ggsave("arial_plot.pdf", arial_plot)
embed_fonts("arial_plot.pdf")
ggsave("jokerman_plot.png", jokerman_plot)
ggsave("jokerman_plot.pdf", jokerman_plot)
embed_fonts("jokerman_plot.pdf")
Run Code Online (Sandbox Code Playgroud)
这会产生以下(正确的)PNG图像:
然而,Arial PDF将所有字符堆叠在一起(Jokerman PDF渲染正确):
此脚本生成以下警告消息.
Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), ... :
font width unknown for character 0x68 …Run Code Online (Sandbox Code Playgroud)