Plotting the debate "Winner"

October 24, 2012

(This article was first published on is.R(), and kindly contributed to R-bloggers)

As a Political Scientist, it could not be more gauche to talk about the Presidential debate in terms of a winner and a loser, but the occasion provides the opportunity to show how to do (at least) three really useful things:

  1. Directly load price and volume data for InTrade contracts. All you need to know is the InTrade contractId, which can be found in the URL of a page like this one, for Barack Obama to win the third Presidential debate.
  2. Convert the character-class time and date from the InTrade .CSV to a POSIXt-class time and date, which many R functions recognize and use in a special way. This is done with parse_date_time from lubridate, which really is as amazing as people say it is. (More on lubridate here.)
  3. Superimpose the price trend over indicators of trade volume, using ggplot2. There is some odd (to me) behavior in the plotting code, meaning that in one place we have to specify the time as.numeric, but it gets the job done.

To leave a comment for the author, please follow the link and comment on their blog: is.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...

Tags: , ,

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)