Fun with twitteR: Osama bin Laden tweets

May 3, 2011

(This article was first published on Travis Nelson's Blog » R, and kindly contributed to R-bloggers)

I thought it would be fun to play around with the R package twitteR , an R API into Twitter.  I decided to take the most prominent news story of the past few days, Osama bin Laden’s death, to see the progression of tweets as news spread.  I quickly found that the max results for the searchTwitter() function were 1500 per day since this is such a big story right now.  I decided to narrow the results by location using the geocode parameter to look at how people in Denver were tweeting.  I used the Colorado State Capitol Building (39.739567,-104.984794) with a radius of 6 miles.  I am still maxing out the results per day, but it looks like a better representation than at a 5 mile radius.  I’m still new to this API so maybe with a little tweaking, I can improve the results.




#Colorado State Capitol Building
geoLocation = '39.739567,-104.984794,6mi'
tweets <- searchTwitter("Osama Bin Laden", n=1500,
     geocode=geoLocation, since='2011-04-30', until='2011-05-01')
tweets <- rbind(tweets, searchTwitter("Osama Bin Laden", n=1500,
     geocode=geoLocation, since='2011-05-01', until='2011-05-02'))
tweets <- rbind(tweets, searchTwitter("Osama Bin Laden", n=1500,
     geocode=geoLocation, since='2011-05-02', until='2011-05-03'))
tweets <- rbind(tweets, searchTwitter("Osama Bin Laden", n=1500,
     geocode=geoLocation, since='2011-05-03'))
times <- sapply(tweets, function(x) format(x$created,
     "%m-%d %H:00",tz = "America/Denver"))
users <- sapply(tweets, function(x) x$screenName)
times <- times[!duplicated(users)] #removing duplicate
counts <- table(times)
bp <- barplot(counts, main="Counts of 'Osama Bin Laden' Tweets by
     Hour\nwithin 6 miles of Colorado State Capitol Building",
     col="lightblue", border=NA, ylim=c(0,300),las=3 )
lines(spline(counts ~ bp), lwd=3, lty="dashed", col="darkblue")

To leave a comment for the author, please follow the link and comment on their blog: Travis Nelson's Blog » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...


Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)