{
  "id": 1137,
  "title": "For R users, what type of plot do you use? and normalization?",
  "url": "/competitions/AlgorithmicTradingChallenge/discussion/1137",
  "author_name": "",
  "post_date": "2011-12-08T10:09:37.270Z",
  "votes": 1,
  "comment_count": 2,
  "views": 2792,
  "content": "<p>This is an R graphing question; I'm spinning my wheels getting a reasonable plot of one row event (<em>bid</em> &amp;\r\n<em>ask</em> prices for timeslots 1..100 in the training set). I'm trying to get the\r\n<em>bid</em> series as solid green bars (downwards) and <em>ask</em> as solid red bars (going upward, which is tricky). Alternatively, I could create a stacked barplot with a pseudoseries\r\n<em>spread=ask-bid </em>(of filled black bars stacked on top of the bid series). Maybe slightly less desirable, because it doesn't plot the series directly.</p>\r\n<ul>\r\n<li>do you use stairstep : <em>plot(..., type='s')</em> ? </li><li>or stacked <em>barplot()</em>? (if so, I don't see how to get the filled ask bars to go upwards)\r\n</li><li>or do you use <a href=\"http://had.co.nz/ggplot2/\">ggplot2</a> , if so which type of plot?\r\n<a href=\"http://had.co.nz/ggplot2/geom_bar.html\">geom_bar</a>, <a href=\"http://had.co.nz/ggplot2/geom_ribbon.html\">\r\ngeom_ribbon</a>, custom qplot ...? </li></ul>\r\n<p>Second question: do you normalize the plot, if so to what? the average width of the bid-ask spread during the predictor window (slots 1..50), rounded to nearest unit? the max width of the bid-ask spread?</p>\r\n<p>Thanks in advance,</p>\r\n<p>Stephen</p>",
  "messages": [
    {
      "id": "7013",
      "postDate": "12/08/2011 10:09:37",
      "content": "<p>This is an R graphing question; I'm spinning my wheels getting a reasonable plot of one row event (<em>bid</em> &amp;\r\n<em>ask</em> prices for timeslots 1..100 in the training set). I'm trying to get the\r\n<em>bid</em> series as solid green bars (downwards) and <em>ask</em> as solid red bars (going upward, which is tricky). Alternatively, I could create a stacked barplot with a pseudoseries\r\n<em>spread=ask-bid </em>(of filled black bars stacked on top of the bid series). Maybe slightly less desirable, because it doesn't plot the series directly.</p>\r\n<ul>\r\n<li>do you use stairstep : <em>plot(..., type='s')</em> ? </li><li>or stacked <em>barplot()</em>? (if so, I don't see how to get the filled ask bars to go upwards)\r\n</li><li>or do you use <a href=\"http://had.co.nz/ggplot2/\">ggplot2</a> , if so which type of plot?\r\n<a href=\"http://had.co.nz/ggplot2/geom_bar.html\">geom_bar</a>, <a href=\"http://had.co.nz/ggplot2/geom_ribbon.html\">\r\ngeom_ribbon</a>, custom qplot ...? </li></ul>\r\n<p>Second question: do you normalize the plot, if so to what? the average width of the bid-ask spread during the predictor window (slots 1..50), rounded to nearest unit? the max width of the bid-ask spread?</p>\r\n<p>Thanks in advance,</p>\r\n<p>Stephen</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "7014",
      "postDate": "12/08/2011 11:24:12",
      "content": "<p>Good question. I didn't do any aggregation, just looked at a few examples, and didn't do anything fancy. For the testing data I used</p>\r\n<pre>testing &lt;- read.csv(&quot;Data/testing.csv&quot;)<br>nt &lt;- 50; nr &lt;- nrow(testing)<br>asknt &lt;- paste(&quot;ask&quot;,1:nt,sep=&quot;&quot;)<br>bidnt &lt;- paste(&quot;bid&quot;,1:nt,sep=&quot;&quot;)<br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(testing[i,match(bidnt,names(testing))],<br>    testing[i,match(asknt,names(testing))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  lines(1:nt,testing[i,match(bidnt,names(testing))],col=&quot;green&quot;,lwd=2)<br>  lines(1:nt,testing[i,match(asknt,names(testing))],col=&quot;red&quot;,lwd=2)<br>}</pre>\r\n<p>Press enter 50000 times if you've nothing else to do. And for (a bit of the) training data I used the following. I even coloured them green and red.</p>\r\n<pre>training &lt;- read.csv(&quot;Data/abitofthetraining.csv&quot;)<br>nt &lt;- 100; nr &lt;- nrow(training)<br>asknt &lt;- paste(&quot;ask&quot;,1:nt,sep=&quot;&quot;)<br>bidnt &lt;- paste(&quot;bid&quot;,1:nt,sep=&quot;&quot;)<br><br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(training[i,match(bidnt,names(training))],<br>    training[i,match(asknt,names(training))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  lines(1:nt,training[i,match(bidnt,names(training))],col=&quot;green&quot;,lwd=2)<br>  lines(1:nt,training[i,match(asknt,names(training))],col=&quot;red&quot;,lwd=2)<br>  abline(v=50)<br>}</pre>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "7015",
      "postDate": "12/08/2011 11:53:07",
      "content": "<p>And here's those lines the you wanted. Though personally I think it looks ugly. Using filled polygons (the second version below) looks much nicer.</p>\r\n<pre>training &lt;- read.csv(&quot;Data/abitofthetraining.csv&quot;)<br>nt &lt;- 100; nr &lt;- nrow(training)<br>asknt &lt;- paste(&quot;ask&quot;,1:nt,sep=&quot;&quot;)<br>bidnt &lt;- paste(&quot;bid&quot;,1:nt,sep=&quot;&quot;)<br><br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(training[i,match(bidnt,names(training))],<br>    training[i,match(asknt,names(training))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  segments(1:nt,as.numeric(training[i,match(bidnt,names(training))]),y1=rep(par(&quot;usr&quot;)[3],nt),col=&quot;red&quot;)<br>  segments(1:nt,as.numeric(training[i,match(asknt,names(training))]),y1=rep(par(&quot;usr&quot;)[4],nt),col=&quot;green&quot;)<br>  abline(v=50)<br>}<br><br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(training[i,match(bidnt,names(training))],<br>    training[i,match(asknt,names(training))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  polygon(c(1:nt,nt:1),c(as.numeric(training[i,match(bidnt,names(training))]),rep(par(&quot;usr&quot;)[3],nt)),col=&quot;red&quot;)<br>  polygon(c(1:nt,nt:1),c(as.numeric(training[i,match(asknt,names(training))]),rep(par(&quot;usr&quot;)[4],nt)),col=&quot;green&quot;)<br>  abline(v=50)<br>}</pre>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 7014,
      "author_name": "alecstephenson",
      "author_url": "",
      "post_date": "12/08/2011 11:24:12",
      "content": "<p>Good question. I didn't do any aggregation, just looked at a few examples, and didn't do anything fancy. For the testing data I used</p>\r\n<pre>testing &lt;- read.csv(&quot;Data/testing.csv&quot;)<br>nt &lt;- 50; nr &lt;- nrow(testing)<br>asknt &lt;- paste(&quot;ask&quot;,1:nt,sep=&quot;&quot;)<br>bidnt &lt;- paste(&quot;bid&quot;,1:nt,sep=&quot;&quot;)<br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(testing[i,match(bidnt,names(testing))],<br>    testing[i,match(asknt,names(testing))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  lines(1:nt,testing[i,match(bidnt,names(testing))],col=&quot;green&quot;,lwd=2)<br>  lines(1:nt,testing[i,match(asknt,names(testing))],col=&quot;red&quot;,lwd=2)<br>}</pre>\r\n<p>Press enter 50000 times if you've nothing else to do. And for (a bit of the) training data I used the following. I even coloured them green and red.</p>\r\n<pre>training &lt;- read.csv(&quot;Data/abitofthetraining.csv&quot;)<br>nt &lt;- 100; nr &lt;- nrow(training)<br>asknt &lt;- paste(&quot;ask&quot;,1:nt,sep=&quot;&quot;)<br>bidnt &lt;- paste(&quot;bid&quot;,1:nt,sep=&quot;&quot;)<br><br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(training[i,match(bidnt,names(training))],<br>    training[i,match(asknt,names(training))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  lines(1:nt,training[i,match(bidnt,names(training))],col=&quot;green&quot;,lwd=2)<br>  lines(1:nt,training[i,match(asknt,names(training))],col=&quot;red&quot;,lwd=2)<br>  abline(v=50)<br>}</pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 7015,
      "author_name": "alecstephenson",
      "author_url": "",
      "post_date": "12/08/2011 11:53:07",
      "content": "<p>And here's those lines the you wanted. Though personally I think it looks ugly. Using filled polygons (the second version below) looks much nicer.</p>\r\n<pre>training &lt;- read.csv(&quot;Data/abitofthetraining.csv&quot;)<br>nt &lt;- 100; nr &lt;- nrow(training)<br>asknt &lt;- paste(&quot;ask&quot;,1:nt,sep=&quot;&quot;)<br>bidnt &lt;- paste(&quot;bid&quot;,1:nt,sep=&quot;&quot;)<br><br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(training[i,match(bidnt,names(training))],<br>    training[i,match(asknt,names(training))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  segments(1:nt,as.numeric(training[i,match(bidnt,names(training))]),y1=rep(par(&quot;usr&quot;)[3],nt),col=&quot;red&quot;)<br>  segments(1:nt,as.numeric(training[i,match(asknt,names(training))]),y1=rep(par(&quot;usr&quot;)[4],nt),col=&quot;green&quot;)<br>  abline(v=50)<br>}<br><br>par(ask=TRUE)<br>for(i in 1:nr) {<br>  plot(c(1:nt,1:nt),c(training[i,match(bidnt,names(training))],<br>    training[i,match(asknt,names(training))]), type=&quot;n&quot;, xlab= &quot;Index&quot;, ylab = &quot;Price&quot;)<br>  polygon(c(1:nt,nt:1),c(as.numeric(training[i,match(bidnt,names(training))]),rep(par(&quot;usr&quot;)[3],nt)),col=&quot;red&quot;)<br>  polygon(c(1:nt,nt:1),c(as.numeric(training[i,match(asknt,names(training))]),rep(par(&quot;usr&quot;)[4],nt)),col=&quot;green&quot;)<br>  abline(v=50)<br>}</pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "7013": "",
    "7014": "",
    "7015": ""
  },
  "source": "meta"
}