Using emoji with highcharter and highcharts

In this minipost we will see that it is not so complicated.
twitter
minipost
highcharts
highcharter
Author

Joshua Kunst Fuentes

Published

January 10, 2021

Post updated on Dec 23, 2022

Let`s try using emoji symbols in highcharter/highcharts.

Fistโ€™s some data:

Code
# devtools::install_github("hadley/emo")
library(emo)
library(tidyverse)
library(rtweet)
library(highcharter)

For download tweets I followed the instructions from https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html

Code
token <- create_token(
  app = "jbktests",
  consumer_key = "consumerkey",
  consumer_secret = "consumer_secret",
  access_token = "access_token",
  access_secret = "access_secret"
)

Chart 1

Using emoji in the axis. In this case is direct, nothing special to do.

Code
# in interactive mode you can avoid/remove the token argument
tweets <- rtweet::search_tweets("#rstats", n = 18000, token = token, include_rts = FALSE)

emoji <- tweets %>%
  mutate(emoji = ji_extract_all(text)) %>%
  unnest(cols = c(emoji)) %>%
  count(emoji, sort = TRUE) 

max_count <- emoji %>% 
  pull(n) %>% 
  max()
Code
hchart(
  emoji, 
  "bar",
  hcaes(emoji, n), 
  name = "Count",
  # dataLabels = list(enabled = TRUE, style = list(fontWeight = "normal"))
  ) %>% 
  hc_xAxis(
    min = 0,
    max = 30,
    scrollbar = list(enabled = TRUE)
    ) %>% 
  hc_yAxis(
    max = max_count,
    title = list(
      text = "Count",
      align = "high"
      )
    ) %>% 
  hc_tooltip(
    headerFormat = "{point.key}",
    pointFormat = " {point.y}"
  ) %>% 
  hc_size(height = 700)

Chart 2

Using emoji as markers.

Code
emoji2 <- tweets %>%
  mutate(emoji = ji_extract_all(text)) %>%
  select(favorite_count, retweet_count, emoji) %>% 
  filter(map_dbl(emoji, length) > 0) %>% 
  unnest(cols = c(emoji)) %>% 
  group_by(emoji) %>% 
  summarise_all(sum) %>% 
  filter(favorite_count*retweet_count > 0) 
  
emoji2
# A tibble: 196 ร— 3
   emoji favorite_count retweet_count
   <chr>          <int>         <int>
 1 โž•               369            80
 2 โšฝ               112            22
 3 โ€ผ๏ธ                 21            15
 4 โฌœ                29            84
 5 โณ                11             6
 6 โคต๏ธ                 16             7
 7 โฌ‡๏ธ                 16             7
 8 โ–ถ๏ธ                300            69
 9 โžก๏ธ                396            81
10 โ˜€๏ธ                 27             5
# โ€ฆ with 186 more rows
Code
hchart(
  emoji2,
  "scatter", 
  hcaes(favorite_count , retweet_count),
  name = "emoji",
  marker = list(
    radius = 0
    ),
  dataLabels = list(
    enabled = TRUE,
    format = "{point.emoji}", 
    allowOverlap = TRUE,
    style = list(fontSize = 20),
    y = 20
    )
  ) %>% 
  hc_xAxis(type = "logarithmic", title = list(text = "Favorites"), minRange = 1) %>% 
  hc_yAxis(type = "logarithmic", title = list(text = "Retweets"), minRange = 1) %>% 
  hc_chart(zoomType = "xy")

Reuse

Citation

BibTeX citation:
@online{kunstfuentes2021,
  author = {Joshua Kunst Fuentes},
  title = {Using Emoji with Highcharter and Highcharts},
  date = {2021-01-10},
  url = {https://jkunst.com/blog/posts/2021-01-10-using-emoji-with-highcharterhighcharts},
  langid = {en}
}
For attribution, please cite this work as:
Joshua Kunst Fuentes. 2021. โ€œUsing Emoji with Highcharter and Highcharts.โ€ January 10, 2021. https://jkunst.com/blog/posts/2021-01-10-using-emoji-with-highcharterhighcharts.