In ggproto, coord$transform did not transform some columns to [0, 1]
<p>I want to create a new Geom type: geom_ohlc(), which is something like Candlestick Charts, to plot the stock open-high-low-close data. </p>

<p>After learning this <a href="http://docs.ggplot2.org/dev/vignettes/extending-ggplot2.html" rel="nofollow">Hadley's article</a>: I tried this:</p>

<pre><code>GeomOHLC &lt;- ggproto(`_class` = "GeomOHLC", `_inherit` = Geom,

                 required_aes = c("x", "op", "hi", "lo", "cl"),

                 draw_panel = function(data, panel_scales, coord){

                   coords &lt;- coord$transform(data, panel_scales)
                   browser() # &lt;&lt;-- here is where I found the problem
                   grid::gList(
                     grid::rectGrob(
                       x = coords$x,
                       y = pmin(coords$op, coords$cl),
                       vjust = 0,
                       width = 0.01,
                       height = abs(coords$op - coords$cl),
                       gp = grid::gpar(col = coords$color, fill = "yellow")
                     ),
                     grid::segmentsGrob(
                       x0 = coords$x,
                       y0 = coords$lo,
                       x1 = coords$x,
                       y1 = coords$hi
                       )
                   )
                 })
    geom_ohlc &lt;- function(data = NULL, mapping = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
    {
      layer(
        geom = GeomOHLC, mapping = mapping, data = data, 
        stat = stat, position = position, show.legend = show.legend, 
        inherit.aes = inherit.aes, params = list(na.rm = na.rm, ...)
      )
    }   
    dt &lt;- data.table(x = 1:10, open = 1:10, high = 3:12, low = 0:9, close = 2:11)
    p &lt;- ggplot(dt, aes(x = x, op = open, hi = high, lo = low, cl = close)) + 
      geom_ohlc() 
    p
</code></pre>

<p>for simplicity, i just do not consider the color of bar.</p>

<p>The result plot is like this:</p>

<p><img src="https://i.stack.imgur.com/1fgbY.png" alt="screenshot"></p>

<p>I add a <code>browser()</code> inside the <code>ggproto</code> function, and I found that the <code>coord$transform</code> did not transform the <code>op</code>, <code>hi</code>, <code>lo</code>, <code>cl</code> aesthetics into interverl [0,1]. How to fix this problem ?</p>

<p>Moreover, is there any other documents about how to create your own Geom type except that Hadley's article ? </p>