尽管有很多关于向R图形添加字体的帖子,我似乎无法做我需要做的事情,它提供了带有内部字体类型的图形的EPS / PDF,称为“VIC”(我有内部字体类型.otf和.ttf)。
这就是我一直在做的......
添加字体:
library("sysfonts")
font.paths('my font path\\')
font.add(family = "VIC",
regular = "VIC-Regular.ttf",
bold = "VIC-Bold.ttf",
italic = "VIC-Italic.ttf",
bolditalic = "VIC-BoldItalic.ttf")
有了这个,我可以在R:
中使用图形中的字体x <- rnorm(1000,1,5)
y <- rnorm(1000,5,20)
plot(x,y, col=1:8,las=1, pch=19, cex=1, xlab="Some label name", ylab="Some label name")
图表看起来很棒,标签和轴上的VIC字体类型完美无缺!
但是,当我尝试导出PDF时:
pdf("H:\\test.pdf", family="VIC")
plot(x,y, xlab="Some label name", ylab="Some label name")
dev.off()
我收到错误消息:
Error in pdf("H:\\test.pdf", family = "VIC") :
unknown family 'VIC'
跑步:
pdf("H:\\test.pdf")
par(family = "VIC")
plot(x,y, xlab="Some label name", ylab="Some label name")
dev.off()
提供了更具信息性的错误:
font family 'VIC' not found in PostScript font database
如何将我的字体添加到PostScript字体数据库?谷歌搜索这导致链接'extrafont'。做
library(extrafont)
extrafont::ttf_import(paths = "my font path\\",
recursive = TRUE,
pattern = NULL)
似乎将VIC字体添加到注册表中:
> loadfonts(device="postscript")
Registering font with R using postscriptFonts(): VIC
Registering font with R using postscriptFonts(): VIC ExtraLight
No regular (non-bold, non-italic) version of VIC ExtraLight Italic. Skipping setup for this font.
Registering font with R using postscriptFonts(): VIC Light
No regular (non-bold, non-italic) version of VIC Light Italic. Skipping setup for this font.
Registering font with R using postscriptFonts(): VIC Medium
No regular (non-bold, non-italic) version of VIC Medium Italic. Skipping setup for this font.
Registering font with R using postscriptFonts(): VIC SemiBold
No regular (non-bold, non-italic) version of VIC SemiBold Italic. Skipping setup for this font.
然而,我仍然得到:
> pdf("H:\\PDF_VIC_19_4_2.pdf", family="VIC")
Error in pdf("H:\\PDF_VIC_19_4_2.pdf", family = "VIC") :
unknown family 'VIC'
我迷路了......
非常感谢任何建议!
吕克