1

I am trying to display emojis as a facet wrap label. However, while the emoji is correctly saved in the dataset, ggplot incorrectly displays the emoji (see example picture below). I have seen emoji's displayed as axis labels however, facet wrap seems to not work.

This post has the same problem but the solution does not work: Unicode in ggplot facet_wrap (en_US.UTF-8 locale)

Here is the minimal reproducible code along with the output I get:

facets <- sprintf(c('✓', emoji("smile")))

set.seed(123)
my_df <- data.frame(x = runif(40), y = runif(40), 
            z = rep(facets, each=20),
            stringsAsFactors = F)

ggplot(my_df, aes(x, y, color=z)) + geom_point() + 
  facet_wrap(~z) +
  theme(legend.position = 'none')

Output

Arm627
  • 11
  • 2
  • If you don't get an answer, maybe you can substitute the emoji by the text ":)" or something in those lines – Ricardo Semião e Castro Oct 23 '22 at 23:57
  • @RicardoSemiãoeCastro I tried doing that as well. By copying the emoji as a string, I tried the unicode as well as using the emojifont package but it seems to be some problem with ggplot. Also really weird how the checkmark is rendered but not the other emojis. – Arm627 Oct 24 '22 at 00:06

1 Answers1

0

Is it what you looking for?

library(ggplot2)
library(emojifont)
facets <- sprintf(c(emoji('heavy_check_mark'), emoji("smile")))

set.seed(123)
my_df <- data.frame(x = runif(40), y = runif(40), 
                    z = rep(facets, each=20),
                    stringsAsFactors = F)

ggplot(my_df, aes(x, y, color=z)) + geom_point() + 
  facet_wrap(~z) +
  theme(legend.position = 'none', strip.text.x=element_text(family='EmojiOne'))

enter image description here

AlienDeg
  • 1,288
  • 1
  • 13
  • 23
  • Oh wow that worked! However, is there any way to keep the color of the emoji? – Arm627 Oct 24 '22 at 16:22
  • what color did you have there? – AlienDeg Oct 24 '22 at 16:40
  • For example the emoji("smile") look like this: but the color goes away in the plot above – Arm627 Oct 24 '22 at 16:53
  • Do you have an example where they look like that on a lot? from the package vignette it seems it's not possible. https://cran.r-project.org/web/packages/emojifont/vignettes/emojifont.html https://github.com/13rac1/emojione-color-font – AlienDeg Oct 25 '22 at 05:47