问题
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
回答1:
@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")
来源:https://stackoverflow.com/questions/38355061/add-a-bold-female-symbol-to-ggplot2-using-annotate