我试图在ggplot图形中使用女性♀和男性♂符号。当我加载extrafont包并运行所需的代码时,它不工作(类似于这个post)。
我在Mac的10.11.6版上,使用R作为Mac的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错误消息:
扫描/库/字体/,/系统/库/字体,~/库/字体/.从.afm文件中提取.ttf文件。Data.frame中的错误(fontfile= ttfiles,FontName = "",stringsAsFactors = FALSE):参数意味着不同的行数: 0,1
和双重核对:
> fonts() #empty
NULL
> fonttable() #empty
data frame with 0 columns and 0 rows,有人知道为什么会发生这种情况吗?我怎样才能让它正常运行?
更新:
或者,我可以使用不同的包(请参阅OP here)来加载杯标。但是,我仍然不能让♀和♂符号出现在我的♀上。Suggestions?
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() 发布于 2019-04-26 21:21:16
showtext应该能够完成这项工作。
library(ggplot2)
library(showtext)
showtext_auto()
female = intToUtf8(9792)
male = intToUtf8(9794)
p = ggplot() +
annotate("text", x = 1, y = 1, label = female, size = 20) +
annotate("text", x = 2, y = 1, label = male, size = 20) +
theme_bw(base_family = "sans")
## On screen
x11()
print(p)
## Save to PDF
ggsave("symbol.pdf", p, width = 9, height = 6)

https://stackoverflow.com/questions/55483861
复制相似问题