Skip to main content

2012 US Presidential Election Timeline in Twitter

Uncategorized
Author

Abe Kazemzadeh

Published

December 14, 2012

I was looking at the spikes in twitter traffic about Obama and Romney during the 2012 US presidential election. So far this is just volumes of tweets containing “obama” and/or (logical or) “romney” (case insensitive), but in the future I would like to do similar plots for sentiment.

electionTimeline_annotated

The data this is based on 315,000,000 tweets, which was more than 1TB when including all the metadata.  Only the subset of these matching “obama” or “romney” were used for the chart, but still it took 11 hours to tabulate the results on my desktop computer (the one that I mentioned in the previous post).

This plot was made using R and Inkscape.  Here’s the input data table, and here’s a gist of the R code :

# Read in data
timeSeriesElectionData <- read.table("twitterElectionTimeline_tsvWithHeader.txt",header=TRUE)

# Attach columns of data as variables in R environment
attach(timeSeriesElectionData)

# open a pdf file for writing
pdf(file="electionTimeline.pdf",height=4,width=12)

# plot the sum of tweets about obama and romney, as a line, with no x-axis ticks, bla bla... 
plot(obama+romney, type='l',xaxt='n',xlab='Date',ylab="Number of Obama and Romney Tweets")

# create a sequence of dates, from Mar. 1 to Dec. 1, by month
d <- seq.Date(from=as.Date('2012-3-01'), to=as.Date('2012-12-01'),by='month')

# find the number of data points:
length(obama)
# output: [1] 1068

# write the dates as axis ticks
axis(side=1,labels=d,at=seq(from=1,to=1068,length.out=10),cex.axis=0.8,las=2)

#close the pdf file
dev.off()

Original code on GitHub Gist


Originally published on abewrites.

clustrmaps.html