<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/using-emojis-as-scatterplot-points/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://statisticaloddsandends.wordpress.com/2018/12/28/using-emojis-as-scatterplot-points/"> R – Statistical Odds &amp; Ends</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Recently I wanted to learn how to use emojis as points in a scatterplot points. It seems like the <a rel="nofollow" href="https://cran.r-project.org/web/packages/emojifont/vignettes/emojifont.html" target="_blank"><code>emojifont</code></a> 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 <a rel="nofollow" href="https://github.com/dill/emoGG" target="_blank"><code>emoGG</code></a>; this post shows how to use this package. (For another example involving fire stations, see <a rel="nofollow" href="https://github.com/kjytay/misc/blob/master/blog/emoGG_example.R" target="_blank">this script</a>.)</p>
<p>Let’s load the packages:</p>
<pre>
library(ggplot2)
library(emoGG)
</pre>
<p>Let’s load a less commonly used small dataset that comes with base R called <code>ToothGrowth</code>:</p>
<pre>
data(&quot;ToothGrowth&quot;)
summary(ToothGrowth)
# len        supp         dose
# Min.   : 4.20   OJ:30   Min.   :0.500
# 1st Qu.:13.07   VC:30   1st Qu.:0.500
# Median :19.25           Median :1.000
# Mean   :18.81           Mean   :1.167
# 3rd Qu.:25.27           3rd Qu.:2.000
# Max.   :33.90           Max.   :2.000
</pre>
<p>Here is the dataset’s description from its documentation:</p>
<blockquote>
<p>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 <code>VC</code>).</p>
</blockquote>
<p>A little esoteric… but it’ll work for our purposes. Let’s make a scatterplot of <code>len</code> vs. <code>dose</code>:</p>
<pre>
ggplot(data = ToothGrowth) +
    geom_point(aes(dose, len))
</pre>
<p><img data-orig-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_point.png?w=456" data-orig-size="397,333" data-medium-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_point.png?w=456?w=300" data-attachment-id="809" data-image-meta="{" data-image-description="" src="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_point.png?w=456" data-permalink="https://statisticaloddsandends.wordpress.com/2018/12/28/using-emojis-as-scatterplot-points/geom_point/" data-large-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_point.png?w=456?w=397" alt="" data-image-title="geom_point" sizes="(max-width: 397px) 100vw, 397px" data-comments-opened="1" class="wp-image-809" data-recalc-dims="1"></p>
<p>To plot emojis instead of points, we use the <code>geom_emoji</code> layer and specify which emoji to use with the <code>emoji</code> option:</p>
<pre>
ggplot(data = ToothGrowth) +
    geom_emoji(aes(dose, len), emoji = &quot;1f439&quot;) +
    labs(x = &quot;Dose (mg/day)&quot;, y = &quot;Tooth length&quot;)
</pre>
<p><img data-orig-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji1.png?w=456" data-orig-size="397,333" data-medium-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji1.png?w=456?w=300" data-attachment-id="810" data-image-meta="{" data-image-description="" src="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji1.png?w=456" data-permalink="https://statisticaloddsandends.wordpress.com/2018/12/28/using-emojis-as-scatterplot-points/geom_emoji1/" data-large-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji1.png?w=456?w=397" alt="" data-image-title="geom_emoji1" sizes="(max-width: 397px) 100vw, 397px" data-comments-opened="1" class="wp-image-810" data-recalc-dims="1"></p>
<p>We can add horizontal jitter to the points manually:</p>
<pre>
ggplot(data = ToothGrowth) +
    geom_emoji(aes(dose + runif(nrow(ToothGrowth), min = -0.2, max = 0.2), 
                   len), emoji = &quot;1f439&quot;)  +
    labs(x = &quot;Dose (mg/day)&quot;, y = &quot;Tooth length&quot;)
</pre>
<p><img data-orig-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji2.png?w=456" data-orig-size="397,333" data-medium-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji2.png?w=456?w=300" data-attachment-id="812" data-image-meta="{" data-image-description="" src="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji2.png?w=456" data-permalink="https://statisticaloddsandends.wordpress.com/2018/12/28/using-emojis-as-scatterplot-points/geom_emoji2/" data-large-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji2.png?w=456?w=397" alt="" data-image-title="geom_emoji2" sizes="(max-width: 397px) 100vw, 397px" data-comments-opened="1" class="wp-image-812" data-recalc-dims="1"></p>
<p>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:</p>
<pre>
# doesn't work
ggplot(data = ToothGrowth) +
    geom_emoji(aes(dose + runif(nrow(ToothGrowth), min = -0.2, max = 0.2), 
                   len), emoji = supp) +
    labs(x = &quot;Dose (mg/day)&quot;, y = &quot;Tooth length&quot;)
</pre>
<p>What we could do is add separate layers manually for each of the 30 guinea pigs. It’s cumbersome but it works…</p>
<pre>
p1 &lt;- geom_emoji(data = subset(ToothGrowth, supp == &quot;OJ&quot;), 
                aes(dose + runif(sum(ToothGrowth$supp == &quot;OJ&quot;), min = -0.2, max = 0.2), 
                   len), emoji = &quot;1f34a&quot;)
p2 &lt;- geom_emoji(data = subset(ToothGrowth, supp == &quot;VC&quot;), 
                 aes(dose + runif(sum(ToothGrowth$supp == &quot;OJ&quot;), min = -0.2, max = 0.2), 
                     len), emoji = &quot;1f48a&quot;)

ggplot() +
    p1 + p2 +
    labs(x = &quot;Dose (mg/day)&quot;, y = &quot;Tooth length&quot;)
</pre>
<p><img data-orig-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji3.png?w=456" data-orig-size="397,333" data-medium-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji3.png?w=456?w=300" data-attachment-id="813" data-image-meta="{" data-image-description="" src="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji3.png?w=456" data-permalink="https://statisticaloddsandends.wordpress.com/2018/12/28/using-emojis-as-scatterplot-points/geom_emoji3/" data-large-file="https://statisticaloddsandends.files.wordpress.com/2018/12/geom_emoji3.png?w=456?w=397" alt="" data-image-title="geom_emoji3" sizes="(max-width: 397px) 100vw, 397px" data-comments-opened="1" class="wp-image-813" data-recalc-dims="1"></p>
<p>How did I find the emoji code to use? <code>emoGG</code> comes with an <code>emoji_search</code> function that helps us with that. For example, to find the code for the orange emoji:</p>
<pre>
emoji_search(&quot;orange&quot;)
# emoji             code     keyword
# 2184 tangerine            1f34a      orange
# 2235    carrot            1f955      orange
# 4092         a            1f170  red-square
# 4093         a            1f170    alphabet
# 4094         a            1f170      letter
# 4130         o             2b55      circle
# 4131         o             2b55       round
# 4364        ng            1f196 blue-square
# 4365        ng            1f196       words
# 4366        ng            1f196       shape
# 4367        ng            1f196        icon
# 5311   georgia 1f1ec\\U0001f1ea          ge
</pre>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://statisticaloddsandends.wordpress.com/2018/12/28/using-emojis-as-scatterplot-points/"> R – Statistical Odds &amp; Ends</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/7YWtXF_TPPI" height="1"></a></div>