r - 我无法使用 font_import 导入字体

标签 r ggplot2 fonts

我正尝试按照 here 中的描述为 ggplot2 图表导入字体.

当我试着用这段代码一 block 一 block 地做时:

font_import(pattern = "Arial.ttf")
y

我收到这个错误:

canning ttf files in C:\windows\Fonts ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 0, 1

我检查过我确实有 Arial 字体: enter image description here

我的问题是什么

最佳答案

我遇到了同样的问题,即尝试使用 font_import() 导入字体 (Zallman Caps) 并收到相同的错误:

"Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) : 
   arguments imply differing number of rows: 0, 1"

经过大量试验和错误,我终于找到了适合我的解决方案,也许它也适合你。

即使我可以在我的 Windows 字体文件夹中看到 Zallman Caps 字体并验证它在 Word 中工作,font_import()list.files() 都不能在那里找到它。我通过输入以下代码设法导入了字体:

font_import(path = "C:/Users/*insert your user name*/AppData/Local/Microsoft/Windows/Fonts", pattern = ".TTF")

我不知道为什么它在主字体目录中对 R 不可见,而我可以在 Windows 文件资源管理器中清楚地看到它,但至少我设法使用此解决方法导入了字体。

关于r - 我无法使用 font_import 导入字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59949572/

相关文章:

r - 将字符串向量转换为 R 中的数据帧

r - ggplot 随着时间的推移每个唯一实例的多线图

r - 使用 ggplot2 和plotly 绘制 3D 棱镜

css - 哪种方式适合定义字体系列?

html - 字体在 Chrome 中有效,但在 Firefox 或 IE 中无效

R:在 data.table 中每个 ID 的开始日期和结束日期之间插入新的每日行

r - R : Error in names(resamples) <- gsub ("^\\.", ""、names(resamples)) 中带有 SVM 的插入符号:尝试在 NULL 上设置属性

r - 绘制时间序列热图时提高 ggplotly 的性能

R:将 dplyr group_by 与 ggplot2 结合使用并更改每个组的标题

ios - 在 UserControl 中使用自定义字体使我的字体变为粗体