R
The emojifont
package is designed to bring
emoji
font to R users and is created for users that are
impatient and relutant to learn.
The package is very simple, pack some emoji fonts (currently only EmojiOne.ttf) and use showtext to render the fonts, then we can use the font in either base plot or ggplot2.
To use emoji
, we need to use their corresponding
unicode. Emoji unicode can be found in http://apps.timwhitlock.info/emoji/tables/unicode,
or searched using search_emoji
function. The
search_emoji
function will return emoji aliases which can be
converted to unicode by emoji
function.
## [1] "smiley" "smile" "sweat_smile" "smiley_cat" "smile_cat"
## [1] "😃" "😄" "😅" "😺" "😸"
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="EmojiOne", size=6)
To make it easy to used with ggplot2
, I implemented a
very simple layer, geom_emoji
, to visualize
emoji
with ggplot2
.
The emojifont
package was initially designed for using
emoji font. I found that FontAwesome is quite
interesting especially in technical world.
The usage is quite similar as using emoji.
set.seed(2016-03-09)
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=T))
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'))
To make it easy to used with ggplot2
, a corresponding
geom_fontawesome
is also provided.
Creating phylomoji is possible using emojifont
and
ggtree
, please refer to the Phylomoji
session in the treedata
book.
RStudio
using a different way to open graphics device
and showtext
is currently incompatible with it.
Since emojifont
use showtext
as backend to
parse emoji font, it also incompatible with RStudio
.
The solution is to manually open a window by calling
X11()
in Linux, quartz()
in Mac or
windows()
in Windows, and create plots on top of that,
instead of the built-in device offered by RStudio
.
Currently, this package support Emoji Font and Font Awesome.
EmojiOne.ttf
is downloaded from https://github.com/eosrei/emojione-color-fontOpenSansEmoji.ttf
is downloaded from https://github.com/MorbZ/OpenSansEmojifontawesome-webfont.ttf
is downloaded from https://github.com/FortAwesome/Font-Awesome.Feel free to fork this package to add your favorite iconic fonts.
If you have any, let me know. Thx!
Here is the output of sessionInfo()
on the system on
which this document was compiled:
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] colorspace_2.1-1 emojifont_0.5.4 ggplot2_3.5.1 prettydoc_0.4.1
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 jsonlite_1.8.9 compiler_4.4.1 highr_0.11
## [5] showtext_0.9-7 jquerylib_0.1.4 scales_1.3.0 yaml_2.3.10
## [9] fastmap_1.2.0 R6_2.5.1 labeling_0.4.3 showtextdb_3.0
## [13] knitr_1.48 tibble_3.2.1 maketools_1.3.1 proto_1.0.0
## [17] munsell_0.5.1 bslib_0.8.0 pillar_1.9.0 rlang_1.1.4
## [21] utf8_1.2.4 cachem_1.1.0 xfun_0.48 sass_0.4.9
## [25] sys_3.4.3 cli_3.6.3 withr_3.0.2 magrittr_2.0.3
## [29] digest_0.6.37 grid_4.4.1 lifecycle_1.0.4 sysfonts_0.8.9
## [33] vctrs_0.6.5 evaluate_1.0.1 glue_1.8.0 farver_2.1.2
## [37] buildtools_1.0.0 fansi_1.0.6 rmarkdown_2.28 tools_4.4.1
## [41] pkgconfig_2.0.3 htmltools_0.5.8.1