2

I'm trying to use emo::ji to display emojis on ggplots but instead of emojis I get white squares.

It works on Rmarkdown, but not on ggplots.

This works:

`r emo::ji("smile")`

emo::ji("smile")

This also works:

a = tidyr::tibble(a = emo::ji("smile"))

tibble

This doesn't:

plot(runif(10), runif(10), pch = emo::ji("smile"), cex = 2)

plot

File encoding is already UTF-8. I read that it could be OS related. I'm on macOS 11.2.1. This didn't help. I spent hours on this and haven't found a solution yet. Would appreciate any help.

 ─ Session info ──────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.1.0 (2021-05-18)
 os       macOS Big Sur 11.2.1        
 system   x86_64, darwin17.0          
 ui       RStudio                     
 language (EN)                        
 collate  pt_BR.UTF-8                 
 ctype    pt_BR.UTF-8                 
 tz       America/Sao_Paulo           
 date     2021-08-07                  

─ Packages ──────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                     
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.1.0)             
 cli           3.0.1      2021-07-17 [1] CRAN (R 4.1.0)             
 crayon        1.4.1      2021-02-08 [1] CRAN (R 4.1.0)             
 DBI           1.1.1      2021-01-15 [1] CRAN (R 4.1.0)             
 digest        0.6.27     2020-10-24 [1] CRAN (R 4.1.0)             
 dplyr         1.0.7      2021-06-18 [1] CRAN (R 4.1.0)             
 ellipsis      0.3.2      2021-04-29 [1] CRAN (R 4.1.0)             
 emo           0.0.0.9000 2021-08-07 [1] Github (hadley/emo@3f03b11)
 evaluate      0.14       2019-05-28 [1] CRAN (R 4.1.0)             
 fansi         0.5.0      2021-05-25 [1] CRAN (R 4.1.0)             
 generics      0.1.0      2020-10-31 [1] CRAN (R 4.1.0)             
 glue          1.4.2      2020-08-27 [1] CRAN (R 4.1.0)             
 htmltools     0.5.1.1    2021-01-22 [1] CRAN (R 4.1.0)             
 knitr         1.33       2021-04-24 [1] CRAN (R 4.1.0)             
 lifecycle     1.0.0      2021-02-15 [1] CRAN (R 4.1.0)             
 lubridate     1.7.10     2021-02-26 [1] CRAN (R 4.1.0)             
 magrittr      2.0.1      2020-11-17 [1] CRAN (R 4.1.0)             
 pillar        1.6.2      2021-07-29 [1] CRAN (R 4.1.0)             
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.1.0)             
 purrr         0.3.4      2020-04-17 [1] CRAN (R 4.1.0)             
 R6            2.5.0      2020-10-28 [1] CRAN (R 4.1.0)             
 Rcpp          1.0.7      2021-07-07 [1] CRAN (R 4.1.0)             
 rlang         0.4.11     2021-04-30 [1] CRAN (R 4.1.0)             
 rmarkdown     2.9        2021-06-15 [1] CRAN (R 4.1.0)             
 rstudioapi    0.13       2020-11-12 [1] CRAN (R 4.1.0)             
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 4.1.0)             
 stringi       1.7.3      2021-07-16 [1] CRAN (R 4.1.0)             
 stringr       1.4.0      2019-02-10 [1] CRAN (R 4.1.0)             
 tibble        3.1.3      2021-07-23 [1] CRAN (R 4.1.0)             
 tidyr         1.1.3      2021-03-03 [1] CRAN (R 4.1.0)             
 tidyselect    1.1.1      2021-04-30 [1] CRAN (R 4.1.0)             
 utf8          1.2.2      2021-07-24 [1] CRAN (R 4.1.0)             
 vctrs         0.3.8      2021-04-29 [1] CRAN (R 4.1.0)             
 withr         2.4.2      2021-04-18 [1] CRAN (R 4.1.0)             
 xfun          0.24       2021-06-15 [1] CRAN (R 4.1.0)             
 yaml          2.2.1      2020-02-01 [1] CRAN (R 4.1.0)  

       
ana.la
  • 109
  • 5
  • I got the same issue when knitting an RMarkdown. What solved the issue for me was to switch to `ragg` by adding `dev="ragg_png"` to the code chunk option. – stefan Aug 07 '21 at 07:55
  • 1
    Tried that, but it made no difference. – ana.la Aug 08 '21 at 20:15

1 Answers1

1

You can use the emojifont package instead.

read more here

install.packages("emojifont")
library(emojifont)

plot(runif(10), runif(10), cex = 0)
text(runif(10), runif(10), labels=emoji('smile'), cex=1.5, col='orange', family='EmojiOne')

enter image description here

With ggplot2:

d <- data.frame(x=runif(10), y=runif(10), label = sample(emoji('smile'), 5, replace=TRUE))

ggplot(d, aes(x, y, label=label)) + geom_text(family="EmojiOne", size=6, color='orange')

enter image description here

KacZdr
  • 1,267
  • 3
  • 8
  • 23
  • 1
    Although this works, it's not exactly what I need since the emojifont package doesn't have all emojis. – ana.la Aug 08 '21 at 20:16
  • 1
    This package contains over 1000 emoticons, you can search them by name with `search_emoji ('some_name')` and maybe you will find the ones you are looking for :) – KacZdr Aug 08 '21 at 20:58