With all the work around sentiment analysis of Trump’s Tweets, I thought that I would add my observation to the discipline. And with vague memories of an analysis of favourability of judges rulings by time of day
I thought I would check Trump’s tweets for negativity by time of day. This code is essentially that used in the blog piece
then tweaked by me to get the hour of the UTC tweet and subtract 5 for East Coast U.S. Time (as a quick and dirty time zone adjustment)
library(twitteR) library(tidyverse) library(tidytext) library(lubridate) api_key = "you_need_to_use_your_own" api_secret = "you_need_to_use_your_own" access_token = "you_need_to_use_your_own" access_token_secret = "you_need_to_use_your_own" options(httr_oauth_cache=F) setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret) trump <- userTimeline("realDonaldTrump", n = 3100, includeRts = TRUE, excludeReplies = FALSE) %>% twListToDF() words <- trump %>% select(id, statusSource, retweetCount, favoriteCount, created, isRetweet, text) %>% unnest_tokens(word, text) %>% mutate(android = stringr::str_detect(statusSource, "Android"), tweethour = hour(created) - 5) %>% select(- statusSource) %>% inner_join(get_sentiments("afinn")) trumphrs <- words %>% filter(android) boxplot(trumphrs$score ~ trumphrs$tweethour, varwidth=TRUE)
As indicated in the code, you would need to user your own Twitter developer details to get the code to run.
Which makes a boxplot like:
Which suggests the most negative tweets are at about 8am, 10am, 1pm, and 4pm East Coast U.S. time. I will speculate there is a food related pattern, but there is a lot of overlap in the box plots, which is not to surprising given the range of the sentiment index and the range of peoples vocabulary.