ggplot - How can I add a ":)" instead of the actual emoji of a smiley face?

43 Views Asked by At

I would like to add within the scale_shape_manual() of a ggplot a smiley face for a given category, but simple, so exactly as ":)". However, I can only find an actual emoji (e.g. here or more options here: https://www.alanwood.net/demos/wgl4.html).

So, for example with a categorical variable with 3 levels, I would have:

scale_shape_manual(values = c(-9786, as.hexmode("3F"), as.hexmode("78")))

But I want that -9786 to be ":)" and not the emoji (codes from: https://www.alanwood.net/demos/wgl4.html)

Any suggestions?

1

There are 1 best solutions below

1
Quinten On

As mentioned by @stefan you can use the geom_text function to display some text (smileys :)) by creating them as a label. Since you didn't provide reproducible example I tried to create one. Here is some reproducible code:

library(ggplot2)
library(scales) # colors of ggplot
ggplot(data = df, aes(x = x, y = y)) +  
  geom_text(aes(color = factor(group), label = label)) +
  scale_color_manual(labels = df$label,
                     values = hue_pal()(4))

Created on 2024-03-25 with reprex v2.0.2


Data

df <- data.frame(x = 1:4,
                 y = 1:4,
                 group = c(1:4),
                 label = c(":)", ";)", ":(", ";("))