Created
March 11, 2016 16:40
-
-
Save hanxue/f9a9f2e20898ec71066d to your computer and use it in GitHub Desktop.
Example of Twitter Word Cloud Using R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got Error in get(arg) : object 'latest_tweet' not found at line "tweets <- homeTimeline(n = 800, sinceID = latest_tweet)"