Wordcloud from Facebook comments

On 3/28/2015 our news station (WPTV) posted about Obama coming to visit South Florida.

Posts about the president always get plenty of negative comments, so I thought it would be fun to display them in a word cloud.

It’s interesting when we get a bunch of “who cares” comments on a story. By taking the time to type out “who cares”, does that mean you do indeed care?

obama word cloud

library(tm)
library(wordcloud)
library(Rfacebook)
library(RColorBrewer) #For the color palette

pal2 <- brewer.pal(8,"Dark2") #Color palette for the word cloud.

# token generated here: https://developers.facebook.com/tools/explorer
#These expire every 2 hours
shell.exec("https://developers.facebook.com/tools/explorer")

token = "xxxx"

data <- getPage("mypage", token=token, n = 25, feed = TRUE)

#I used the above dataset to pick out a post id that I wanted to analyze.
#data$id
id <- "xxxxx" #this is the post id.
post <- getPost(id, token)

text <- paste(unlist(post$comment$message), collapse = " ")
text <- sapply(text,function(row) iconv(row, "latin1", "ASCII", sub=""))

x11()
wordcloud(text, col= pal2, min.freq = 10)

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

Blog at WordPress.com.

Up ↑

%d bloggers like this: