Load the required packages

library(twitteR); library(tidyverse)
library(lubridate);library(tidytext)
ge <- read.csv("GE2020_07_03.csv")

Break #GE2020 data into media and public

media <- c("sgelection", "STcom", "asiaonecom", "BusinessTimes",
           "ChannelNewsAsia", "YahooSG", "MothershipSG")
'%ni%' <- Negate('%in%')
ge_media <- ge %>% filter(isRetweet==FALSE) %>%
  filter(screenName %in% media)
ge_public <- ge %>% filter(isRetweet==FALSE) %>%
  filter(screenName %ni% media)

Visualize count of tweets by screenName (top 10)

top10users <- ge_public %>% count(screenName, sort = T) %>% top_n(10) %>%
  ungroup()
## Selecting by n
ggplot(top10users, aes(fct_inorder(screenName), n)) +
  geom_bar(stat = "identity") +
  ggtitle("#GE2020 Top 10 tweeters as at 3 July") +
  theme(axis.text.x = element_text(angle = 45))

Convert ge_pubic tweets into a tibble

tweets_text <- ge_public$text
length(tweets_text)
## [1] 1341
tweets_tbl <- tibble(line =1:1341, text = tweets_text)
twitter_stop_words <- tibble(word = c("https","t.co","rt","amp",
                                      "rstats","gt"), lexicon = "twitter")
ge_stop_words <- tibble(word = c("ge2020", "party", "singapore", "election",
                                 "#singapore", "july", "10", "day",
                                 "sgelection", "singaporevotes", "sgvotes",
                                 "sgelections", "sgelection2020"),
                        lexixon = "GE")
data("stop_words")

Public opinion of GE2020 (Bigram)

bi_po <- tweets_tbl %>%
  unnest_tokens(bigram, text, token = "ngrams", n = 2)
bigrams_separated <- bi_po %>%
  separate(bigram, c('word1',  'word2'), sep = " ")
bigrams_filtered <- bigrams_separated %>%
  filter(!word1 %in% stop_words$word) %>%
  filter(!word2 %in% stop_words$word) %>%
  filter(!word1 %in% twitter_stop_words$word) %>%
  filter(!word2 %in% twitter_stop_words$word) %>%
  filter(!word1 %in% ge_stop_words$word) %>%
  filter(!word2 %in% ge_stop_words$word)
bigrams_filtered %>% count(word1, word2, sort = T)
## # A tibble: 2,861 x 3
##    word1   word2               n
##    <chr>   <chr>           <int>
##  1 east    coast              82
##  2 jamus   lim                27
##  3 mao     god                22
##  4 dr      chee               21
##  5 god     omg                21
##  6 heng    swee               21
##  7 cdc     commidescochons    19
##  8 coast   grc                19
##  9 omaogod cdc                19
## 10 omg     omaogod            19
## # ... with 2,851 more rows

Mr Jamus Lim has been the star candidate for GE2020

Public Opinion of Mr Jamus Lim

jamus <- tweets_tbl %>% 
  unnest_tokens(sentence, text, token = "sentences") %>%
  filter(str_detect(sentence, "jamus lim"))
c(jamus[,2])
## $sentence
##  [1] "after making a fancam of jamus lim yesterday, i had to make another one of our queen @raeesahkhanwpsg #ge2020… https://t.co/fkchlrcvel"      
##  [2] "hypebeast tan cheng bock was not what i'd expected, but i didn't expect vivian to fall in love with jamus lim, or h… https://t.co/vdpxkdqebi"
##  [3] "headline for asiaone piece in the morning was “wp's jamus lim wins over the internet after his performance in ge202… https://t.co/jltyoeznls"
##  [4] "did tcb just steal jamus lim's line #ge2020"                                                                                                 
##  [5] "feels like jamus lim debate performance last night is gonna spearhead wp's potential strong showing in #ge2020"                              
##  [6] "unpopular opinion: jamus lim reminds me of the cabbage patch kid. #respectthewp #nodisrespect #sgelection #ge2020 #wpftw"                    
##  [7] "#singapore #ge2020 #singaporevotes  wp's jamus lim @jamuslim wins hearts post debate; fans amazed by his degrees, v… https://t.co/httoqygus2"
##  [8] "professor jamus lim, you just won over so many people overnight."                                                                            
##  [9] "#singapore #ge2020  wp's jamus lim @jamuslim  is trending on twitter today morning https://t.co/0p0txkula3"                                  
## [10] "\"(jamus lim) @jamuslim  was clearly more nervous at the start and was gesticulating too much for my liking but his… https://t.co/x6k7upxn1t"
## [11] "#singapore #ge2020  wp's jamus lim @jamuslim  put up an outstanding performance during yesterday's political debate… https://t.co/lhtq5vskbv"
## [12] "now y’all have see him here’s more #ge2020: wp’s #jamus lim shares how singapore’s education system is like a...… https://t.co/2adx9tl9hh"   
## [13] "what we’re trying to deny pap is a blank cheque (<u+7a7a><u+5934><u+652f><u+7968>), wp’s jamus lim on #ge2020  https://t.co/gcbqldm0pk"      
## [14] "jamus lim so cute #ge2020"                                                                                                                   
## [15] "jamus lim is an incredibl… https://t.co/fazcyabgq3"                                                                                          
## [16] "on tonight's debate: jamus lim shined towards the end."                                                                                      
## [17] "this jamus lim is dam good!!"                                                                                                                
## [18] "if you're voting in sengkang grc, do yourself a favour and watch this for jamus lim!"                                                        
## [19] "wp jamus lim is a gem."                                                                                                                      
## [20] "i'm officially simping dr jamus lim after that debate."                                                                                      
## [21] "im an athiest, but thank god we have jamus lim <u+2728> #ge2020"                                                                             
## [22] "jamus lim for prime minister #ge2020 https://t.co/o0q2skz6xp"                                                                                
## [23] "the workers’ party dr jamus lim, good sia!"                                                                                                  
## [24] "miss congeniality award goes to jamus lim #ge2020"                                                                                           
## [25] "jamus lim's response to vivian's accusing the @wpsg of being pap-lite is perfect: when deciding on who should bear… https://t.co/lj2psaxdah" 
## [26] "can we vote in dr jamus lim into parliment?"                                                                                                 
## [27] "jamus lim is srsly killing it #ge2020"                                                                                                       
## [28] "francis yuen and jamus lim are steady performers."