Skip to content

Instantly share code, notes, and snippets.

@DrSkippy
Created January 24, 2012 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrSkippy/1671753 to your computer and use it in GitHub Desktop.
Save DrSkippy/1671753 to your computer and use it in GitHub Desktop.
R script for plotting time series volume data with ggplot, gridextra
#!/usr/bin/env Rscript
#
# Plot time series volume data
# install.packages("ggplot2", dependencies = TRUE )
# install.packages("gridExtra", dependencies = TRUE )
library(ggplot2)
library(gridExtra)
X <-read.delim("./twitter.timeline.csv.byhour.csv", sep=",", header=TRUE)
# parse datetime strings
X$date <- as.POSIXct(X$time)
summary(X)
# ts is unix style timestamp
sub0 <- X[ (X$ts > 1293814803 & X$ts < 1293901203) , ]
sub1 <- X[ (X$ts > 1325350803 & X$ts < 1325437203) , ]
summary(sub0)
summary(sub1)
p0 <- qplot(sub0$date, sub0$count, geom="bar", stat="identity", xlab="2010: 12/31 - 1/1 GMT", ylab="tweets/hr") + scale_y_continuous(limits = c(0, 1100000))
p1 <- qplot(sub1$date, sub1$count, geom="bar", stat="identity", xlab="2011: 12/31 - 1/1 GMT", ylab="tweets/hr") + scale_y_continuous(limits = c(0, 1100000))
png(filename = "./NYTweets-World-2011.png", width = 600, height = 600, units = 'px')
print(
p1
)
dev.off()
png(filename = "./NYTweets-World-2011v2010.png", width = 600, height = 600, units = 'px')
print(
grid.arrange(p0, p1, ncol = 1, main="Compare 2010 vs 2011")
)
dev.off()
png(filename = "./NYTweets-Growth-2011v2010.png", width = 600, height = 600, units = 'px')
print(
qplot(sub0$count, sub1$count, xlab="2010 tweets/hr", ylab="2011 tweets/hr") +
geom_smooth(method=lm,se=FALSE) +
scale_y_continuous(limits = c(0, 1100000)) +
scale_x_continuous(limits = c(0, 1100000))
)
dev.off()
time ts count
2010-12-31 00:00:00 1293771600 19322
2010-12-31 01:00:00 1293775200 21496
2010-12-31 02:00:00 1293778800 25291
2010-12-31 03:00:00 1293782400 24624
2010-12-31 04:00:00 1293786000 23237
2010-12-31 05:00:00 1293789600 21986
2010-12-31 06:00:00 1293793200 21444
2010-12-31 07:00:00 1293796800 22990
2010-12-31 08:00:00 1293800400 25117
2010-12-31 09:00:00 1293804000 29619
2010-12-31 10:00:00 1293807600 42066
2010-12-31 11:00:00 1293811200 63381
2010-12-31 12:00:00 1293814800 81804
2010-12-31 13:00:00 1293818400 123443
2010-12-31 14:00:00 1293822000 146642
2010-12-31 15:00:00 1293825600 283513
2010-12-31 16:00:00 1293829200 354815
2010-12-31 17:00:00 1293832800 497250
2010-12-31 18:00:00 1293836400 280226
2010-12-31 19:00:00 1293840000 198366
2010-12-31 20:00:00 1293843600 163837
2010-12-31 21:00:00 1293847200 166959
2010-12-31 22:00:00 1293850800 205120
2010-12-31 23:00:00 1293854400 302115
2011-01-01 00:00:00 1293858000 321040
2011-01-01 01:00:00 1293861600 216749
2011-01-01 02:00:00 1293865200 239693
2011-01-01 03:00:00 1293868800 210898
2011-01-01 04:00:00 1293872400 205134
2011-01-01 05:00:00 1293876000 386917
2011-01-01 06:00:00 1293879600 253332
2011-01-01 07:00:00 1293883200 140896
2011-01-01 08:00:00 1293886800 157679
2011-01-01 09:00:00 1293890400 84815
2011-01-01 10:00:00 1293894000 74467
2011-01-01 11:00:00 1293897600 73061
2011-01-01 12:00:00 1293901200 74922
2011-01-01 13:00:00 1293904800 79421
2011-01-01 14:00:00 1293908400 91177
2011-01-01 15:00:00 1293912000 102802
2011-01-01 16:00:00 1293915600 99842
2011-01-01 17:00:00 1293919200 97269
2011-01-01 18:00:00 1293922800 88556
2011-01-01 19:00:00 1293926400 77660
2011-01-01 20:00:00 1293930000 65541
2011-01-01 21:00:00 1293933600 58986
2011-01-01 22:00:00 1293937200 51691
2011-01-01 23:00:00 1293940800 47411
2011-12-30 23:00:00 1325304000 8
2011-12-31 00:00:00 1325307600 40327
2011-12-31 01:00:00 1325311200 39938
2011-12-31 02:00:00 1325314800 45133
2011-12-31 03:00:00 1325318400 47009
2011-12-31 04:00:00 1325322000 45705
2011-12-31 05:00:00 1325325600 45841
2011-12-31 06:00:00 1325329200 44520
2011-12-31 07:00:00 1325332800 44430
2011-12-31 08:00:00 1325336400 50774
2011-12-31 09:00:00 1325340000 66330
2011-12-31 10:00:00 1325343600 93642
2011-12-31 11:00:00 1325347200 137345
2011-12-31 12:00:00 1325350800 167380
2011-12-31 13:00:00 1325354400 237606
2011-12-31 14:00:00 1325358000 278185
2011-12-31 15:00:00 1325361600 242886
2011-12-31 16:00:00 1325365200 510205
2011-12-31 17:00:00 1325368800 954878
2011-12-31 18:00:00 1325372400 612498
2011-12-31 19:00:00 1325376000 416047
2011-12-31 20:00:00 1325379600 354282
2011-12-31 21:00:00 1325383200 383924
2011-12-31 22:00:00 1325386800 462609
2011-12-31 23:00:00 1325390400 698534
2012-01-01 00:00:00 1325394000 807354
2012-01-01 01:00:00 1325397600 541200
2012-01-01 02:00:00 1325401200 593989
2012-01-01 03:00:00 1325404800 510280
2012-01-01 04:00:00 1325408400 501744
2012-01-01 05:00:00 1325412000 1062100
2012-01-01 06:00:00 1325415600 648903
2012-01-01 07:00:00 1325419200 352523
2012-01-01 08:00:00 1325422800 363534
2012-01-01 09:00:00 1325426400 214594
2012-01-01 10:00:00 1325430000 194403
2012-01-01 11:00:00 1325433600 187932
2012-01-01 12:00:00 1325437200 194569
2012-01-01 13:00:00 1325440800 208644
2012-01-01 14:00:00 1325444400 254083
2012-01-01 15:00:00 1325448000 259707
2012-01-01 16:00:00 1325451600 248718
2012-01-01 17:00:00 1325455200 234990
2012-01-01 18:00:00 1325458800 218121
2012-01-01 19:00:00 1325462400 193565
2012-01-01 20:00:00 1325466000 163479
2012-01-01 21:00:00 1325469600 151588
2012-01-01 22:00:00 1325473200 133513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment