Skip to content

Instantly share code, notes, and snippets.

@hanxue
Created March 11, 2016 16:40
Show Gist options
  • Save hanxue/f9a9f2e20898ec71066d to your computer and use it in GitHub Desktop.
Save hanxue/f9a9f2e20898ec71066d to your computer and use it in GitHub Desktop.
Example of Twitter Word Cloud Using R
library(twitteR)
library(ROAuth)
library(tm)
library(wordcloud)
my.key <- "xxx"
my.secret <- "xxx"
access.token <- "123-xxx"
access.token.secret <- "xxx"
setup_twitter_oauth(my.key, my.secret, access.token, access.token.secret)
tweets <- homeTimeline(n = 800, sinceID = latest_tweet)
timeline_list <- sapply(tweets, function(x) x$getText())
corpus <- Corpus(VectorSource(timeline_list))
corpus <- tm_map(corpus,
content_transformer(function(x) iconv(x, to='UTF-8', sub='byte')),
mc.cores=1)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, content_transformer(removePunctuation))
corpus <- tm_map(corpus, content_transformer(removeNumbers))
corpus <- tm_map(corpus, content_transformer(function(x) removeWords(x, stopwords())))
wordcloud(corpus, min.freq=7)
@vigneshprajapati
Copy link

got Error in get(arg) : object 'latest_tweet' not found at line "tweets <- homeTimeline(n = 800, sinceID = latest_tweet)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment