Skip to content

Instantly share code, notes, and snippets.

@mjbommar
Created February 20, 2011 18:58
Show Gist options
  • Save mjbommar/836208 to your computer and use it in GitHub Desktop.
Save mjbommar/836208 to your computer and use it in GitHub Desktop.
# @author: Michael J Bommarito II
# @date: Feb 20, 2011
# @email: michael.bommarito@gmail.com
# @packages: gridExtra, ggplot2
library(gridExtra)
library(ggplot2)
setwd('/data/workspace/blog/cn220/')
# Load and pre-process #cn220
tweets <- unique(read.table('data/tweets_cn220.csv', sep="\t", quote="", comment.char="",
stringsAsFactors=FALSE, header=FALSE, nrows=100000))
names(tweets) <- c("id", "date", "user", "text")
tweets$date <- as.POSIXct(strptime(tweets$date, "%a, %d %b %Y %H:%M:%S %z", tz = "GMT"))
# Plot the figure after binning tweets within 5 minutes
ggplot(data=tweets, aes(date)) +
geom_bar(aes(fill=..count.., colour=..count..), alpha=0.5, size=0.5, binwidth=60*5) +
scale_x_datetime("Date", major="1 day", minor="6 hours", tz="GMT") +
scale_y_continuous("Number of tweets") +
opts(title="#cn220", legend.position="none")
ggsave(file='fig/cn220.pdf', width=8, height=6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment