使用注释将粗体女性符号添加到ggplot2 [英] Add a bold female symbol to ggplot2 using annotate
本文介绍了使用注释将粗体女性符号添加到ggplot2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在情节中使用女性符号♀.这是相当模糊的(嗯,在我的实际图形上看起来是模糊的),所以我希望将其变为大胆的面孔.
I'm trying to use the female symbol, ♀ in my plot. It's pretty faint (well, it looks faint on my actual graph), so I was hoping to make it bold face.
df <- data.frame(x = c(0, 1), y = c(0, 1))
ggplot(df, aes(x, y)) + geom_point() +
theme_bw() +
annotate("text", x = 0.5, y = 0.7, label = "2016 ♀",
size = 7, hjust = 0, colour = "grey50")
我尝试了以下方法,但似乎都没有效果:
I've tried the following, but none seem to work:
ggplot(df, aes(x, y)) + geom_point() +
annotate("text", x = 0.5, y = 0.7, label = "2016~bold(♀)",
size = 7, hjust = 0, parse = TRUE)
# error message: Error in parse(text = as.character(lab)) : <text>:1:11: unexpected '<'
#1: 2016~bold(<
^
ggplot(df, aes(x, y)) + geom_point() +
annotate("text", x = 0.5, y = 0.7, label = "2016~bold(u2640)",
size = 7, hjust = 0, parse = TRUE)
ggplot(df, aes(x, y)) + geom_point() +
annotate("text", x = 0.5, y = 0.7, label = "2016~bold(\u2640)",
size = 7, hjust = 0, parse = TRUE)
I also found this post, but I'm not sure if I can modify the following code to work within ggplot?
plot(df)
text( locator(1), "\\VE", vfont=c("sans serif","bold"), xpd=TRUE) # Venus
推荐答案
@Axeman的评论帮助我找到了答案-我不知道您可以加载其他软件包来获取ggplot2的更多字体.谢谢!我使用了以下代码:
@Axeman's comment helped me find an answer - I didn't realize you could load in other packages to get more fonts for ggplot2. Thanks! I used the following code:
install.packages("extrafont")
library(extrafont)
font_import() # Prepare for this to take several minutes
loadfonts(device = "win")
ggplot(df, aes(x, y)) + geom_point() +
theme_bw() +
annotate("text", x = 0.5, y = 0.7, label = "2016 ♀",
size = 7, hjust = 0, colour = "grey50", family = "Calibri", fontface = "bold")
这篇关于使用注释将粗体女性符号添加到ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文