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
If you want to annotate your plot or figure with labels, there are two basic options: text() will allow you to add labels to the plot region, and mtext() will allow you to add labels to the margins. For the plot region, to add labels you need to specify the coordinates and the label.
@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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With