The latest sentiment from Ashraf Ghani, after admitting defeat to the Taliban
Enter the authentication details below
Authenticate with Twitter
api_key <- "your_api_key"
api_secret <- "your_api_secret"
access_token <- "your_access_token"
access_token_secret <- "your_access_token_secret"
Scraping twitter of AsHraf Ghani use twitter account "@ashrafghani"
In this case we only scrapt 500 tweet as for saving memory
Saving data in directory as file text
Some text need cleaning before the next process, then saving file as tex.file Please note that the classifying the polarity and emotion of the tweets may take a few minutes
some_txt <- read.table("d:/data/asr_some_txt.text")
# classify emotion
class_emo = classify_emotion(some_txt, algorithm="bayes", prior=1.0)
## Warning in TermDocumentMatrix.SimpleCorpus(x, control): custom functions are
## ignored
# get emotion best fit
emotion = class_emo[,7]
# substitute NA's by "unknown"
emotion[is.na(emotion)] = "unknown"
# classify polarity
class_pol = classify_polarity(some_txt, algorithm="bayes")
## Warning in TermDocumentMatrix.SimpleCorpus(x, control): custom functions are
## ignored
# get polarity best fit
polarity = class_pol[,4]
sent_df = data.frame(text=some_txt, emotion=emotion,
polarity=polarity, stringsAsFactors=FALSE)
sent_df = within(sent_df, emotion, polarity)
Dari grafik 1 terlihat, emotion "joy" jauh lebih banyak dari pada emotion "anger" dan "disgust",
dari grafik 2 terlihat 70% sentimen positif, 20% sentimen negatif dan sisanya 10 % netral, menunjukkan
bahwa sampai saat ini Presiden Afganistan Ashraf Ghani masih disegani.