# emojifont: using emoji font in R

The emojifont package is designed to bring emoji font to R users. It packs emoji fonts and uses showtext to render the fonts so they can be used in base plots or ggplot2.

## Installation

Get the released version from CRAN:

    install.packages("emojifont")

Or the development version from GitHub:

    ## install.packages("devtools")
    devtools::install_github("GuangchuangYu/emojifont")

# Emoji characters

To use emoji, we need to use their corresponding unicode. Emoji unicode can be found in https://apps.timwhitlock.info/emoji/tables/unicode, or searched using `search_emoji`. `search_emoji` returns emoji aliases which can be converted to unicode by `emoji`.

    search_emoji("smile")

    [1] "smiley"      "smile"       "sweat_smile" "smiley_cat"  "smile_cat"

    emoji(search_emoji("smile"))

    [1] "😃" "😄" "😅" "😺" "😸"

# Emoji in R plot

## base plot

    set.seed(123)
    x <- rnorm(10)
    set.seed(321)
    y <- rnorm(10)
    plot(x, y, cex = 0)
    text(x, y, labels = emoji("cow"), cex = 1.5, col = "steelblue", family = "OpenMoji")

## ggplot2

    d <- data.frame(
      x = x, y = y,
      label = sample(c(emoji("cow"), emoji("camel")), 10, replace = TRUE),
      type = sample(LETTERS[1:3], 10, replace = TRUE)
    )

    library(ggplot2)
    ggplot(d, aes(x, y, color = type, label = label)) +
      geom_text(family = "OpenMoji", size = 6)

To make it easy to use with ggplot2, a simple layer `geom_emoji` is provided.

    ggplot() + geom_emoji("rose", color = "steelblue") + theme_void()

    x <- seq(0, 2 * pi, length = 30)
    y <- sin(x)
    ggplot() + geom_emoji("heartbeat", x = x, y = y, size = 10)

# Emoji in tables

You can also use emoji within HTML tables by placing Unicode emoji into cells. Here we use `knitr::kable()` to render a simple table.

    library(emojifont)
    library(knitr)

    df <- data.frame(
      name  = c("Cow", "Camel", "Heartbeat"),
      emoji = emoji(c("cow", "camel", "heartbeat")),
      stringsAsFactors = FALSE
    )

    kable(df, format = "html")

name | emoji
--- | ---
Cow | 🐮
Camel | 🐫
Heartbeat | 💓

# Font Awesome

The package also supports Font Awesome icons.

    library(ggplot2)
    set.seed(20160309)
    fa <- fontawesome(c("fa-github", "fa-weibo", "fa-twitter", "fa-android", "fa-coffee"))
    d <- data.frame(
      x = rnorm(20),
      y = rnorm(20),
      label = sample(fa, 20, replace = TRUE)
    )

    ggplot(d, aes(x, y, color = label, label = label)) +
      geom_text(family = "fontawesome-webfont", size = 6) +
      xlab(NULL) + ylab(NULL) +
      theme(legend.text = element_text(family = "fontawesome-webfont"))

A corresponding `geom_fontawesome` is also provided.

    ggplot() + geom_fontawesome("fa-github", color = "black") + theme_void()

# phylomoji

Creating phylomoji is possible using `emojifont` and `ggtree`, please refer to: https://yulab-smu.top/treedata-book/chapter8.html#phylomoji.

# Limitation

RStudio uses a different graphics device handling and `showtext` may be incompatible with it. Since `emojifont` uses `showtext` as backend to parse emoji font, it may also be incompatible with RStudio. Consider manually opening a device (`X11()` in Linux, `quartz()` in macOS or `windows()` in Windows).

# Note

Currently, this package supports Emoji Font and Font Awesome.

- `OpenMoji-Black.ttf` is downloaded from https://github.com/hfg-gmuend/openmoji
- `fontawesome-webfont.ttf` is downloaded from https://github.com/FortAwesome/Font-Awesome.

Feel free to fork this package to add your favorite iconic fonts.

# Bugs/Feature requests

If you have any, let me know: https://github.com/GuangchuangYu/emojifont/issues.

# Session info

Here is the output of `sessionInfo()` on the system on which this document was compiled:

    sessionInfo()

    R version 4.5.2 (2025-10-31 ucrt)
    Platform: x86_64-w64-mingw32/x64
    Running under: Windows 11 x64 (build 26200)

    Matrix products: default
      LAPACK version 3.12.1

    locale:
    [1] LC_COLLATE=C
    [2] LC_CTYPE=Chinese (Simplified)_China.utf8
    [3] LC_MONETARY=Chinese (Simplified)_China.utf8
    [4] LC_NUMERIC=C
    [5] LC_TIME=Chinese (Simplified)_China.utf8

    time zone: Asia/Shanghai
    tzcode source: internal

    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base

    other attached packages:
    [1] knitr_1.51      ggplot2_4.0.2   emojifont_0.6.0

    loaded via a namespace (and not attached):
     [1] vctrs_0.7.1        cli_3.6.5          rlang_1.1.7        xfun_0.56
     [5] otel_0.2.0         showtextdb_3.0     sysfonts_0.8.9     generics_0.1.4
     [9] proto_1.0.0        S7_0.2.1           jsonlite_2.0.0     labeling_0.4.3
    [13] glue_1.8.0         htmltools_0.5.9    scales_1.4.0       rmarkdown_2.30
    [17] grid_4.5.2         tibble_3.3.1       evaluate_1.0.5     fastmap_1.2.0
    [21] yaml_2.3.12        lifecycle_1.0.5    compiler_4.5.2     dplyr_1.2.0
    [25] RColorBrewer_1.1-3 pkgconfig_2.0.3    farver_2.1.2       digest_0.6.39
    [29] R6_2.6.1           tidyselect_1.2.1   showtext_0.9-7     pillar_1.11.1
    [33] magrittr_2.0.4     withr_3.0.2        tools_4.5.2        gtable_0.3.6

ub.com/GuangchuangYu/emojifont/issues>.

# Session info

Here is the output of `sessionInfo()` on the system on which this document was compiled:

    sessionInfo()

    R version 4.5.2 (2025-10-31 ucrt)
    Platform: x86_64-w64-mingw32/x64
    Running under: Windows 11 x64 (build 26200)

    Matrix products: default
      LAPACK version 3.12.1

    locale:
    [1] LC_COLLATE=C
    [2] LC_CTYPE=Chinese (Simplified)_China.utf8
    [3] LC_MONETARY=Chinese (Simplified)_China.utf8
    [4] LC_NUMERIC=C
    [5] LC_TIME=Chinese (Simplified)_China.utf8

    time zone: Asia/Shanghai
    tzcode source: internal

    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base

    other attached packages:
    [1] knitr_1.51      ggplot2_4.0.2   emojifont_0.6.0

    loaded via a namespace (and not attached):
     [1] vctrs_0.7.1        cli_3.6.5          rlang_1.1.7        xfun_0.56
     [5] otel_0.2.0         showtextdb_3.0     sysfonts_0.8.9     generics_0.1.4
     [9] proto_1.0.0        S7_0.2.1           jsonlite_2.0.0     labeling_0.4.3
    [13] glue_1.8.0         htmltools_0.5.9    scales_1.4.0       rmarkdown_2.30
    [17] grid_4.5.2         tibble_3.3.1       evaluate_1.0.5     fastmap_1.2.0
    [21] yaml_2.3.12        lifecycle_1.0.5    compiler_4.5.2     dplyr_1.2.0
    [25] RColorBrewer_1.1-3 pkgconfig_2.0.3    farver_2.1.2       digest_0.6.39
    [29] R6_2.6.1           tidyselect_1.2.1   showtext_0.9-7     pillar_1.11.1
    [33] magrittr_2.0.4     withr_3.0.2        tools_4.5.2        gtable_0.3.6