Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible to separate polygons by a line in the data consisting only of <code>NA</code>.</p> <pre><code>library(reshape2) library(ggplot2) z &lt;- data.frame( date=date, min=pmin(x, y), max=pmax(x, y), series=ifelse(x&gt;y, 1, 2) ) # Helper function to create closed polygon, optionally adding NA line at bottom rdata &lt;- function(dat, addNA=FALSE){ rdat &lt;- dat[nrow(dat):1, ] ret &lt;- rbind( data.frame(x= dat$date, y= dat$max, series= dat$series), data.frame(x=rdat$date, y=rdat$min, series=rdat$series) ) if(addNA) ret &lt;- rbind(ret, c(NA, NA, NA)) ret } # Closed polygon 1 rz &lt;- rdata(z) #Closed polygon 2 z2 &lt;- z rlez &lt;- rle(z$series)$lengths z2$chunk &lt;- rep(seq_along(rlez), times=rlez) rz2 &lt;- ddply(z2, .(chunk), rdata, addNA=TRUE) rz2 &lt;- rz2[rz2$series!=1, ] </code></pre> <p>Create plot</p> <pre><code>ggplot(rz, aes(x, y, fill="Less than")) + geom_polygon() + geom_polygon(data=rz2, aes(x, y, fill="Greater than")) + scale_fill_discrete("Legend") + xlab("Date") + ylab("Value") </code></pre> <p><img src="https://i.stack.imgur.com/KrmLr.png" alt="enter image description here"></p> <hr> <p>PS. I don't know what your data represents in real life, but my hunch is you can visualize it better (or at least as well), with much less effort if you use <code>geom_linerange</code> instead of polygons.</p> <pre><code>ggplot(z, aes(x=date, ymin=min, ymax=max, colour=factor(series))) + geom_linerange(size=5) </code></pre> <p><img src="https://i.stack.imgur.com/3qfYh.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload