JBGruber / rwhatsapp

An R package for working with WhatsApp data 💬
94 stars 19 forks source link

emoji on Mac #3

Closed gav888 closed 4 years ago

gav888 commented 4 years ago

Emoji would not show up using Rstudio 1.2.5001 with R 3.6.1 on Mac Os.

Thank you

JBGruber commented 4 years ago

Not entirely sure what your problem is here as there are a number of ways to look at the emojis in RStudio. Do you mean in the Console? The output you should get there would look like this:

library("rwhatsapp")
library("dplyr")
library("tidyr")
chat <- rwa_read(system.file("extdata", "sample.txt", package = "rwhatsapp"))
chat %>% 
  select(emoji, emoji_name) %>% 
  unnest(cols = c(emoji, emoji_name))
#> # A tibble: 332 x 2
#>    emoji                  emoji_name                     
#>    <chr>                  <chr>                          
#>  1 <U+263A>                     smiling face                   
#>  2 "\U0001f44c\U0001f3fb" OK hand: light skin tone       
#>  3 "\U0001f605"           grinning face with sweat       
#>  4 "\U0001f600"           grinning face                  
#>  5 "\U0001f603"           grinning face with big eyes    
#>  6 "\U0001f604"           grinning face with smiling eyes
#>  7 "\U0001f601"           beaming face with smiling eyes 
#>  8 "\U0001f606"           grinning squinting face        
#>  9 "\U0001f605"           grinning face with sweat       
#> 10 "\U0001f602"           face with tears of joy         
#> # ... with 322 more rows

In the Viewer (View(chat)) you should be able to see actual emojis in the text column (but not in the emoji column as this is a list which is rendered a little differently):

image

If you follow my vignette (vignette("Text_Analysis_using_WhatsApp_data", package = "rwhatsapp")) you should also be able to see emojis in the plots.

Which of the above causes trouble for you? Or are you trying to do anything not covered above?

gav888 commented 4 years ago

Hi there, thanks for the quick reply. I cannot see the emoji when plotting their frequencies by user in the plot window using Rstudio. Attached what I see.

Screenshot 2019-10-15 at 10 31 53
JBGruber commented 4 years ago

But otherwise your output is the same as above?

gav888 commented 4 years ago

Yes, only in the plot emoji are showing up.

Il giorno mar 15 ott 2019 alle 11:25 Johannes Gruber < notifications@github.com> ha scritto:

But otherwise your output is the same as above?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JBGruber/rwhatsapp/issues/3?email_source=notifications&email_token=AFROCOKIALBXBUSJ3F5FOC3QOWD73A5CNFSM4JAGKXNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBICHII#issuecomment-542122913, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFROCOMU3C3A5YCH2UNSF5LQOWD73ANCNFSM4JAGKXNA .

-- Sent from my mobile

JBGruber commented 4 years ago

I think that the problem here is that the default font for ggplot2 on macOS does not support emoji characters (It looks good on Linux and OK on Windows). See this SO question and answer. It would be great if you or anyone reading this could test the solution with the emojifont package and let me know if it works. I could then add a note to the readme and vignette.

JBGruber commented 4 years ago

I recently came across a blog post by someone using the package. He found a cool way to get around the problem, namely looking up pngs and including them in the plot via ggimage. I like the idea and just pushed an update to the package which makes looking up the pngs easier. Here is how this would look like (only works with newest GitHub version so far):

library(rwhatsapp)
library(dplyr)
library(tidyr)
library(ggplot2)
library(purrr)
library(ggimage)

chat <- rwa_read(system.file("extdata", "sample.txt", package = "rwhatsapp"))

emojis <- emojis %>% # data built into package
  mutate(emoji_url = paste0("https://abs.twimg.com/emoji/v2/72x72/", 
                            tolower(hex_runes), ".png"))

chat %>% 
  unnest(emoji) %>% 
  count(emoji, sort = TRUE) %>%
  head() %>% 
  left_join(emojis, by = "emoji") %>% 
  ggplot(aes(x = reorder(name, n), y = n)) +
  geom_col(width = 0.2) +
  geom_image(aes(image = emoji_url)) +
  ylab("") + xlab("") +
  ggtitle("Most often used emojis") +
  coord_flip() +
  theme_bw()

Created on 2019-10-26 by the reprex package (v0.3.0)

gav888 commented 4 years ago

Thanks a lot Johannes, I will try it out.

Best wishes, Giuseppe


Dr Giuseppe A. Veltri Personal email: ga.veltri@gmail.com Work email: giuseppe.veltri@unitn.it Personal Webpage On 26 Oct 2019, 11:31 +0200, Johannes Gruber notifications@github.com, wrote:

I recently came across a blog post by someone using the package. He found a cool way to get around the problem, namely looking up pngs and including them in the plot via ggimage. I like the idea and just pushed an update to the package which makes looking up the pngs easier. Here is how this would look like (only works with newest GitHub version so far): library(rwhatsapp) library(dplyr) library(tidyr) library(ggplot2) library(purrr) library(ggimage)

chat <- rwa_read(system.file("extdata", "sample.txt", package = "rwhatsapp"))

emojis <- emojis %>% # data built into package mutate(emoji_url = paste0("https://abs.twimg.com/emoji/v2/72x72/", tolower(hex_runes), ".png"))

chat %>% unnest(emoji) %>% count(emoji, sort = TRUE) %>% head() %>% left_join(emojis, by = "emoji") %>% ggplot(aes(x = reorder(name, n), y = n)) + geom_col(width = 0.2) + geom_image(aes(image = emoji_url)) + ylab("") + xlab("") + ggtitle("Most often used emojis") + coord_flip() + theme_bw() Created on 2019-10-26 by the reprex package (v0.3.0) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.