Last active
August 29, 2015 14:19
-
-
Save davidcoallier/7213b24bd748ed9fba71 to your computer and use it in GitHub Desktop.
RSA Conference Twitter Term Cloud
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("wordcloud") | |
library("tm") | |
# You running Windows? It's RSA... you probably are so this is for you. | |
# download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem") | |
# Go to https://dev.twitter.com/apps and get your keys from your register app there. | |
consumer_key <- 'YOUR CONSUMER KEY' | |
consumer_secret <- 'YOUR SECRET CONSUMER KEY' | |
access_token <- 'YOUR ACCESS TOKEN' | |
access_secret <- 'YOU SECRET TOKEN' | |
options(httr_oauth_cache=TRUE) | |
setup_twitter_oauth(consumer_key, | |
consumer_secret, | |
access_token, | |
access_secret) | |
# If you're running window, uncomment the cacert above and stick it here as a param. | |
search <- searchTwitter("#RSAC", n=750) | |
tweets.text.orig <- sapply(search, function(x) x$getText()) | |
tweets.text <- sapply(search, function(x) x$getText()) | |
# Replace blank space (“rt”) | |
tweets.text <- gsub("rt", "", tweets.text) | |
tweets.text <- gsub("RT", "", tweets.text) | |
# Remove RSAC and RSAC2015 | |
tweets.text <- gsub("RSAC", "", tweets.text) | |
tweets.text <- gsub("rsac", "", tweets.text) | |
tweets.text <- gsub("RSAC2015", "", tweets.text) | |
tweets.text <- gsub("rsac2015", "", tweets.text) | |
# Replace @UserName | |
#tweets.text <- gsub("@\\w+", "", tweets.text | |
tweets.text <- gsub("^RT (@[[:alnum:]_]*) ", "", tweets.text) | |
# Remove punctuation | |
tweets.text <- gsub("[[:punct:]]", "", tweets.text) | |
# Remove links | |
tweets.text <- gsub("http\\w+", "", tweets.text) | |
# Remove html entity amp terms | |
tweets.text <- gsub("amp", "", tweets.text) | |
# Remove tabs | |
tweets.text <- gsub("\t", "", tweets.text) | |
# Remove blank spaces at the beginning | |
tweets.text <- gsub("^ ", "", tweets.text) | |
# Remove blank spaces at the end | |
tweets.text <- gsub(" $", "", tweets.text) | |
tweets.text.corpus <- Corpus(VectorSource(tweets.text)) | |
tweets.text.corpus <- tm_map(tweets.text.corpus, function(x)removeWords(x,stopwords())) | |
wordcloud( | |
tweets.text.corpus, | |
min.freq=3, | |
scale=c(7,0.5), | |
colors=brewer.pal(8, "Dark2"), | |
random.color= TRUE, | |
random.order = FALSE, | |
max.words = 150 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment