Sentiment Analysis of Tweets
June 10, 2020.
Two days back I got curious about the Twitter API. I worked with a few APIs (using R) in the past but had never chanced upon using Twitter data. Additionally, Twitter provided a rich source of "what people are talking about". I searched and found a very easy to use package for R called rTweet. This package's simplicity and easiness blew my mind.
I got down into it and found several useful functions like search_tweets(), stream_tweets() and get_timeline(). Of course, there are many more functions, have a look at their reference list.
But, why just stop there? tidytext allows very easy to use unigram sentiment analysis. I thought of finding the "positive" and "negative" words used on Twitter.
To start with, I tracked Kerala's elephant murder: an incident in Kerala where an elephant died allegedly due to crackers blasting in its mouth. This incident had grabbed national and international attention bringing organisations like PETA to the forefront.
I first searched for last 10,000 tweets on Twitter, did some cleaning and finally analysed for sentiments.
R codes used for using Twitter's API and generating plots are presented before the plots.
So basically, hardly anyone asked why the person did what they did. If it was even purposeful. Everyone just made a smiley face. A sad smiley face.
Why stop there?
I thought of analysing the tweets by two world leaders: Narendra Modi (our PM) and Donald Trump (US President).
Clearly, Modi uses many more "positive" words than Trump. Many of Modi's negative words are also probably used in positive and hopeful sentences: poor, needy, etc. Trump's characteristic with his fake (news). They both are using words associated with pandemic: virus, crisis, panic, attack, etc.
Here's a proportion comparison of the overall sentiment.
There's a marked difference between how the two leaders - Narendra Modi and Donald Trump - tweet. Around 75% positive for Modi; 40% for Trump. Of course, I could go on comparing more but I exceeded the Twitter request and have to wait for another 15 minutes. Plus, my aim -- of basic understanding as to how to use API and unigram seniment analysis -- was achieved.
Have a great day!