Plotting emojis in R can be as easy as plotting regular text. The idea is to use
the remoji package to obtain emoji strings,
and to use the showtext package
to draw the symbols. The fontemoji
package loads the
OpenSansEmoji font
(included in the package) and registers it to the showtext
database with
the family name "emoji", so that emojis can be plotted using any text drawing
functions in R.
Below is a quick example:
library(showtext)
library(fontemoji)
library(remoji)
showtext.auto()
set.seed(123)
x11()
plot(1, type = "n", xlim = c(0, 12), ylim = c(0, 12),
xlab = "Days left towards deadline", ylab = "Tasks to do")
text(rnorm(20, 7, 2), rnorm(20, 4, 2), emoji("smile"), col = "red",
cex = 2, family = "emoji")
text(rnorm(20, 4, 2), rnorm(20, 7, 2), emoji("cry"), col = "steelblue",
cex = 2, family = "emoji")
The names of emoji symbols can be found in the Emoji cheat sheet.
Want some ggplot2
-flavored plots? The idea is the same:
library(showtext)
library(fontemoji)
library(remoji)
library(ggplot2)
showtext.auto()
dat = data.frame(x = emoji(c("+1", "-1")), y = c(1000, 100))
x11()
ggplot(dat, aes(x = x, y = y)) +
geom_bar(aes(fill = x), stat = "identity", width = 0.5) +
scale_fill_hue("", labels = sub_emoji(c("Good! :satisfied:",
"Oh no... :disappointed:"))) +
xlab("") + ylab("Votes") + ggtitle("How Do You Like This Package?") +
theme(axis.text.x = element_text(family = "emoji", size = 30),
legend.text = element_text(family = "emoji", size = 20),
legend.key.size = grid::unit(1, "cm"),
title = element_text(size = 20))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.