Plotting the debate "Winner"

[This article was first published on is.R(), and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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().

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)