我尝试在ggplot
图中使用女性♀和男性♂符号。当我加载extrafont
包并运行所需代码时,它不起作用(类似于这个帖子)。
我使用的是Mac OS X 10.11.6版本,并使用R for Mac OS X 3.5.2版本。
install.packages("extrafont")
library(extrafont)
extrafont::loadfonts(device="pdf")
extrafont::font_import(pattern="CALIBRI") #pattern that has the ♀ and ♂ symbols
#when I run this as font_import() alone fonts() is still empty
错误信息:
扫描 /Library/Fonts/、/System/Library/Fonts 和 ~/Library/Fonts/ 中的 ttf 文件... 从 ttf 文件中提取 .afm 文件... 在 data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) 中出现错误: arguments imply differing number of rows: 0, 1
双重检查:
> fonts() #empty
NULL
> fonttable() #empty
data frame with 0 columns and 0 rows
请问有人知道为什么会出现这种情况,以及如何使它正常运行?
更新:
另外,我可以使用不同的包来加载Calibri字体(请参见 这里 中的OP)。 但是,我仍然无法在我的ggplot中显示♀和♂符号。 有建议吗?
install.packages('showtext', dependencies = TRUE)
library(showtext)
font_add_google("Montserrat", "Montserrat")
font_add_google("Roboto", "Roboto")
font_paths()
font_files()
# syntax: font_add(family = "<family_name>", regular = "/path/to/font/file")
font_add("Calibri", "calibri.ttf")
font_families()
showtext_auto()