Main menu

Post navigation

Using emojis as scatterplot points

Recently I wanted to learn how to use emojis as points in a scatterplot points. It seems like the emojifont package is a popular way to do it. However, I couldn’t seem to get it to work on my machine (perhaps I need to install the font manually?). The other package I found was emoGG; this post shows how to use this package. (For another example involving fire stations, see this script.)

Let’s load the packages:

library(ggplot2)
library(emoGG)

Let’s load a less commonly used small dataset that comes with base R called ToothGrowth:

The response is the length of odontoblasts (cells responsible for tooth growth) in 60 guinea pigs. Each animal received one of three dose levels of vitamin C (0.5, 1, and 2 mg/day) by one of two delivery methods, orange juice or ascorbic acid (a form of vitamin C and coded as VC).

A little esoteric… but it’ll work for our purposes. Let’s make a scatterplot of len vs. dose:

ggplot(data = ToothGrowth) +
geom_point(aes(dose, len))

To plot emojis instead of points, we use the geom_emoji layer and specify which emoji to use with the emoji option:

I wasn’t able to find an elegant way to have different emojis printed for different points. For example, this dataset contains 30 guinea pigs fed by orange juice and 30 fed by ascorbic acid: we might want different emojis to represent these two groups. The following code does not work:

The geom_emoji layer does have a size option that you can specify, but it looks like it can’t be data dependent… You’re probably better off trying the emojifont package (see other comment in for this post).

Actually, I’d say that if you want the size to reflect some data value, it’s probably best to use regular points instead of emojis; it’ll be easier for the reader to compare observations.

Thanks so much for the advice on how to assign different emojis to different groups! Is there a way to add stat_smooth(lm) lines to an emoGG scatterplot? I’ve been struggling with this and it seems like it should not be so difficult!