Rio2016 Wordcloud

Originally done on July 27, 2016


What's a Wordcloud?

A visualization analysis tool in performing sentiment analysis. A collection of words are gathered and the size of each word is represented by its font size relative to less frequent ones.




What data are we going to use?

We pulled 500 tweets that contained the hashtag Rio2016.

R Code:

#First, install and load R packages
install.packages("twitteR")
require(twitteR)
require(RCurl)
require(tm)
require(wordcloud)
#next, get the necessary deets from Twitter API and then assign values
consumerkey <- "secret"
consumersecret <- "secret"
accesstoken <- "secret"
accesssecret <- "secret"
#Ready for handshake
setup_twitter_oauth(consumerkey, consumersecret, accesstoken, accesssecret)
#Time to mine
RioTweets <-searchTwitter("Rio2016", n=100, lang = "en")
RioTweets
str(RioTweets)
RioTweets[1:5]
Rio500 <-searchTwitter('Rio2016', lang="en", n=500, resultType = "recent")
class(Rio500)
Rio500_text <- sapply (Rio500, function(x) x$getText())
str(Rio500_text)
class(Rio500_text)
str(Rio500)
str(Rio500_text)
RioCorpus <-Corpus(VectorSource(Rio500_text))
RioCorpus
inspect(RioCorpus[1])
inspect(Rio500_text[1:3])
inspect(RioCorpus[3])
#Hmm "Inspect" won't seem to work anymore.
?inspect
insp
#REPLACEMENT FOR "inspect"
as.character(RioCorpus[10])
Rio_Clean <- tm_map(RioCorpus, removePunctuation)
Rio_Clean <- tm_map(Rio_Clean, content_transformer(tolower))
Rio_Clean <- tm_map(Rio_Clean, removeWords, stopwords(kind= "english"))
as.character (Rio_Clean[10])
#so far, so good for cleaning
Rio_Clean <- tm_map(Rio_Clean, removeNumbers)
#Time to remove all the empty spaces left by the edits
Rio_Clean <- tm_map(Rio_Clean, stripWhitespace)
#Maybe remove really obvious words like "RIO" and "Olympics"
Rio_Clean <- tm_map(Rio_Clean, removeWords, c("rio", "Olympics", "2016"))
#Now, to create a wordcloud
wordcloud(Rio_Clean)
wordcloud(Rio_Clean)
require(wordcloud)
wordcloud(Rio_Clean)
wordcloud(Rio_Clean, random.order = F, scale = c(4, 0.5))
wordcloud(Rio_Clean, random.order = F, col = "red")
wordcloud(Rio_Clean, random.order = F, color = rainbow(50))
wordcloud(Rio_Clean, random.order = F, col = rainbow (50), scale = c(6, 0.5))
view raw rio2016.R hosted with ❤ by GitHub

Comments

  1. Casino and Sports Betting - Drmcd
    Get unbiased & honest casino 울산광역 출장안마 reviews 전주 출장마사지 and information for Casino and 보령 출장마사지 Sports 제천 출장샵 Betting, Inc. - Check 의왕 출장마사지 back for upcoming games, promotions and payout! Rating: 4 · ‎Review by Drmcd

    ReplyDelete

Post a Comment