How to add emoji in ggplot2 title?

Hi everyone,

How can I add emojis to a ggplot2 title. All the examples I found online only show how to use emojis as geoms or how to insert them in the axis texts. This is what I attempted but the final result is two hollow rectangles:

EDIT: I'm running Linux. My distribution is based on Ubuntu (it's Pop OS).

ggplot2::ggplot(data = mtcars, mapping = ggplot2::aes(x = wt, y = mpg)) +
  ggplot2::geom_point() +
  ggplot2::labs(title = emo::ji("sun")) +
  ggplot2::theme(plot.title = ggtext::element_markdown()) 

Rplot

You need to use the Unicode codepoint for the emoji you want - for example, a smiley face is Unicode 1F600. So you can put a smiley face in a plot like so:

library(ggplot2)
library(magrittr)

mtcars %>% 
    ggplot(aes(x = disp, y = cyl)) + 
    geom_jitter() + 
    labs(
        title = '\U1F600' # Smiley face is Unicode U+1F600
    )

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.