Summary

Output 1: Twitter trend analysis

1-1. Prepare for analysis

library(rtweet)
## access token method: create token and save it as an environment variable
create_token(
  app = "XXXXXXXXXXXXXXXXXXXXXXXXX",
  consumer_key = "XXXXXXXXXXXXXXXXXXXXXXXX",
  consumer_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  access_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)

1-2. get tweets by searching teenager’s “slang”s

  • If we want to do time series analysis, we can collect more data on Twitter, although there is some extent of limit on API
## define the area of UK as a circle
location <- '54.834318,-2.666795,600km'

## keywords from 'netsanity.net'
## https://netsanity.net/teen-slang-parents-guide/
keywords <- c("bae","low-key","skurt","throw shade","straight fire",
              "sip tea","down in the DM","Netflix ‘n Chill","NIFOC","CU46","GNOC","420",
              "thicc","finna","boujee","AF","OG","yeet")

kw_tw <- search_tweets2(keywords, n=500, geocode=location) ## search tweets by keywords

save(kw_tw, file="./kw_tw.rdata")
save(keywords, file="./keywords.rdata")

1-3. plot frequent hashtags and mentions

load("./kw_tw.rdata")
load("./keywords.rdata")
library(quanteda)
## Package version: 1.4.3
## Parallel computing: 2 of 12 threads used.
## See https://quanteda.io for tutorials and examples.
## 
## Attaching package: 'quanteda'
## The following object is masked from 'package:utils':
## 
##     View
## hashtags
dfm_hash <- dfm(corpus(kw_tw$text), select = "#*") ## create dfm
#tstat_freq_hash <- textstat_frequency(dfm_hash)

textplot_wordcloud(dfm_hash, min_count = 15, random_order = FALSE,
                   rotation = .25)

## mentions
dfm_mention <- dfm(corpus(kw_tw$text), select = "@*")
cols <- grep(paste(keywords, collapse = "|"), colnames(dfm_mention)) ## eliminate search keywords
#tstat_freq_mention <- textstat_frequency(dfm_mention[,-cols])

textplot_wordcloud(dfm_mention[,-cols], min_count = 15, random_order = FALSE,
                   rotation = .25)