问题描述
为了将字体名称为Calibri的ggplots保存到pdf文件中,我尝试使用extrafont
包,以便能够在ggplot2中使用此字体类型.
For saving ggplots with font name Calibri to pdf files, I tried to use the extrafont
package in order to be able to use this font type within ggplot2.
这些是我采取的步骤:
font_import()
获取所有字体后(在此过程中似乎没有什么错),我得到了这个错误:
After getting all the fonts (during that proces nothing seems wrong), I get this error:
Scanning afm files in <<library path>>/extrafontdb/metrics
Error in if (grepl("Bold", weight)) { : argument is of length zero
连同这些错误:
Warning messages:
1: In readLines(srcfile) :
invalid input found on input connection 'C:<<path>>\AppData\Local\Temp\26\RtmpANG4o2/fonts/ahronbd.afm'
2: In readLines(srcfile) :
incomplete final line found on 'C:<<path>>\AppData\Local\Temp\26\RtmpANG4o2/fonts/ahronbd.afm'
etc.
当我运行此代码时:
loadfonts()
fonts()
输出为NULL
,当我尝试使用ggsave()
将ggplot保存为pdf时,错误提示:
and when I try to save a ggplot as a pdf using ggsave()
, the error says:
Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
我想最后一个错误并不令人惊讶,因为字体表似乎是空的.
I guess that last error is not that surprising as the font table seems empty.
这里出了什么问题以及如何解决这个问题?
What's going wrong here and how can this problem be solved?
编辑,我以为我找到了解决方案.当我使用loadfonts(device="win")
而不是loadfonts()
时,一开始似乎一切都很好,但是我错了. fonts()
仍然为空.
EDIT I thought I found the solution. When I use loadfonts(device="win")
instead of loadfonts()
all seemed to go well at first, but I was wrong. fonts()
is still empty.
推荐答案
对于其中的任何激怒搜索,我在Windows上都遇到了同样的问题,并使用以下方法解决了该问题:
For any exasperated searches out there, I had the same issue on Windows, and solved it with:
font_import(paths = "C:/Path_to_font")
现在应填充fonts()
.我在字体预览和相关设置中找到了字体的路径,然后单击相关的字体.大概您的大多数字体都在同一位置.
Now fonts()
should populate. I found the path to fonts in Font preview and related settings and clicking on the relevant font. Presumably most of your fonts are in the same place.
这篇关于使用extrafont程序包检索Windows字体后,“字体"表仍为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!