library(wordcloud)
require(twitteR)
library(ggmap)
library(httr)
library(dplyr)
library(purrr)
library(twitteR)
library(tidyr)
library(lubridate)
library(scales)
library(knitr)
setup_twitter_oauth(comkey,comsec,actok,acsec) ## Hidden keys used
## [1] "Using direct authentication"
get3<-function(usr="realDonaldTrump"){
d1<- userTimeline(usr,n=3200, excludeReplies= TRUE, includeRts=FALSE)
d1<- tbl_df(map_df(d1, as.data.frame))
d2<- userTimeline(usr,n=3200,maxID= min(d1$id), excludeReplies= TRUE, includeRts=FALSE)
d2<- tbl_df(map_df(d2, as.data.frame))
d3<- userTimeline(usr,n=3200,maxID= min(d2$id), excludeReplies= TRUE, includeRts=FALSE)
d3<- tbl_df(map_df(d3, as.data.frame))
d<-rbind(d1,d2,d3)
d
}
trump<-get3()
obama<-get3("BarackObama")
# trump_tweets <- userTimeline("realDonaldTrump", n = 3200,maxID= "1016638035281219584", excludeReplies= TRUE)
# d2 <- tbl_df(map_df(trump_tweets, as.data.frame))
#
# ob<-userTimeline("BarackObama",n=3200, excludeReplies= TRUE, includeRts=FALSE)
# ob <- tbl_df(map_df(ob, as.data.frame))
Obama tweeted far less frequently in 2018 than Donald Trump. The gigure below shows a sctter plot of the favourite counts for each tweet with a trend line Fitted. Donald Trump’s “base” of twitter likers is stable at around only 100,000. Trump does have a lot of followers on Twitter, but very few of them actually like what he writes. Obama’s likes fluctuate depending on what he actually has to say, but are around ten times higher than Donald Trump. And … Obama is not the president!
library(plotly)
obama %>% filter(created>min(trump$created)) ->obama
d<-rbind(trump,obama)
d<-d[!duplicated(d), ]
g1<-ggplot(d,aes(x=created,y=favoriteCount,col=screenName))
g1<-g1 + geom_point() +geom_smooth(se=FALSE)
g1
There is a lot more that could be done to analyse these data, that I just downloaded and plotted quickly onn 7 September 2018 after seeing Obama speak about democratic values on CNN.
dt(d)