7

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")

Plot with faint female symbol

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 
rici
  • 234,347
  • 28
  • 237
  • 341
Nova
  • 5,423
  • 2
  • 42
  • 62
  • 1
    You can add `fontface = 'bold'` to the `annotate` call, and `2016` will look bold, but `♀` looks the same on my screen. My guess is that the font just doesn't have a bold representation for that character? – Axeman Jul 13 '16 at 14:57
  • Yeah, if you use "2016~(bold(infinity))" the infinity sign doesn't get bolded either... – Nova Jul 13 '16 at 15:00
  • 1
    You could try if other `family`s do have bold faces for those. – Axeman Jul 13 '16 at 15:07

1 Answers1

8

@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")

enter image description here

Nova
  • 5,423
  • 2
  • 42
  • 62
  • Hi, How did you know family is an argument of annotate? ?annotate does not tell me that. – Alvaro Morales Mar 09 '21 at 02:18
  • Hi @AlvaroMorales, in the help file you'll see in the list of arguments the `...,` argument. When you read the documentation it says, " `Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3.` " The family argument is just another aesthetic, so it works here. – Nova Mar 10 '21 at 13:24