Twitter Analysis Redefined

Because code keeps changing on Twitter


#dev.twitter.com and apps.twitter.com to generate these tokens
#install.packages("twitteR")
#install.packages("ROAuth")
#PACKAGES
library(twitteR)
library(ROAuth)
#ACCESS URLS
reqURL <- "https://api.twitter.com/oauth/request_token&quot;
accessURL <- "https://api.twitter.com/oauth/access_token&quot;
authURL <- "https://api.twitter.com/oauth/authorize&quot;

#ACCESS KEYS
consumerKey <- "4LEjfrnbzMQvxpJzRKnx6v0JM"
consumerSecret <- "aCsJA6jEHhpqFioKmxwtu9BzMm0TnOFQyZv6mgCUo1j82PzRIn"
access_token="3232641518-IFIlyB5oJ7QbFXT3arO218BWbycGMA6q5NO1b7k"
access_secret='XPfpH3l6QjCnRxpZwHtMbRMqnwmhmxlZqFZxnxgEg35K4'

#HANDSHAKE
setup_twitter_oauth(consumerKey,
consumerSecret,
access_token="3232641518-IFIlyB5oJ7QbFXT3arO218BWbycGMA6q5NO1b7k",
access_secret='XPfpH3l6QjCnRxpZwHtMbRMqnwmhmxlZqFZxnxgEg35K4')

a=searchTwitter("delhi", n=2000)
tweets_dfa = twListToDF(a)
tweets_dfa
b=searchTwitter("mumbai", n=200)
tweets_dfb = twListToDF(b)
c=searchTwitter("bangalore", n=200)
tweets_dfc = twListToDF(c)
tweets=rbind(tweets_dfa,tweets_dfb,tweets_dfc)
#tweets
write.csv(tweets,file="tweets.csv")
head(tweets)
library(tm)
library(wordcloud)
b=Corpus(VectorSource(tweets$text), readerControl = list(language = "eng"))
b=tm_map(b, PlainTextDocument)
inspect(b)
b<- tm_map(b, content_transformer(tolower))
#Changes case to lower case
b<- tm_map(b, stripWhitespace) #Strips White Space
b <- tm_map(b, removePunctuation) #Removes Punctuation
inspect(b)
tdm <- TermDocumentMatrix(b)
m1 <- as.matrix(tdm)
v1<- sort(rowSums(m1),decreasing=TRUE)
d130,]
wordcloud(d2$word,d2$freq,colors =brewer.pal(7,"Set1"))

Rplot

Author: Ajay Ohri

http://about.me/ajayohri

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s