# Analyze Twitter Data Using R

**R-Chart**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

*numbers*of nodes. The .dot and .graphml formats

*do*appear to retain this data. You can also plot the graph a variety of ways within R itself (which is what is demonstrated below).

The graph displayed is static and cannot be manipulated or rearranged in any way. However, you can create an interactive version of the plot by calling the tkplot function for the graph. The individual nodes can be arranged by clicking and dragging them. However, you might instead opt for one of the automatic layouts available that implement various algorithms for drawing graphs.

The Reingold / Tilford algorithm results in an arrangement like the following:

The Kamada-Kawai algorithm by contrast renders as follows:

There are many other ways you can analyze Twitter data using R. There are an extensive collection of R packages dedicated to natural language processing tasks. The following example relies upon the OpenNLP and openNLPmodels.en packages.

library(openNLP)

library(twitteR)

# Replace the user and password below

sess <- initSession('YOUR_TWITTER_USER','PASSWORD')

sea <- searchTwitter("#rstats")

# Cycle through the list and get the text from the tweets for analysis

names(sea)=c(‘tweet’)

textdata=vector()

for (i in 1:length(sea)) {textdata=append(textdata,tokenize(text(sea[[i]])))}

# limit to entries that include alpha characters

textdata=factor(textdata)

textdata=textdata[grep(“[a-zA-Z]”,textdata)]

# Only include tokens that appear more than three times

s=summary(textdata)

subset=s[s>3]

# Set the chart options so that we can see the y axis

par(las=2,cex=.9,mar=c(11, 2, 4, 2) + 0.1)

barplot(subset,names=names(subset))

**leave a comment**for the author, please follow the link and comment on their blog:

**R-Chart**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.