Skip to content

Instantly share code, notes, and snippets.

@sckott
Created December 13, 2011 15:49
Show Gist options
  • Save sckott/1472619 to your computer and use it in GitHub Desktop.
Save sckott/1472619 to your computer and use it in GitHub Desktop.
Code for searching Twitter using the twitteR #rstats package.
require(plyr); require(stringr); require(ggplot2); require(lubridate); require(twitteR)
datout_1 <- searchTwitter("I work for the internet", n = 1500, since='2011-11-11', until='2011-12-12')
datout_2 <- searchTwitter("I work for the internet", n = 1500, since='2011-11-13', until='2011-12-14')
datoutdf <- ldply(c(datout_1, datout_2), function(x) x$toDataFrame(), .progress="text")
actual <- grep("I work for the internet", datoutdf[,1], ignore.case=T)
datoutdf2 <- datoutdf[actual,]
datoutdf2$newtime <- round_date(datoutdf2[,4], "hour")
datoutdf2_ <- ddply(datoutdf2, .(newtime), summarise,
numtweets = length(newtime))
ggplot(droplevels(datoutdf2_), aes(newtime, numtweets)) +
theme_bw(base_size=18) +
geom_line(color="red") +
labs(x='\nTime', y='Number of tweets\n') +
opts(title="Tweets containing 'I work for the internet'")
ggsave("iworkfortheinternet.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment