title: ggplot: geom_facet() by slope of geom_line()
body: <p>Is there a way to <code>facet_wrap()</code> by the slope of a <code>geom_line</code> in R or ggplot, such that for each <code>geom_line</code>, all regions of that line with positive slope are placed in one facet, all regions with negative slope are placed in another facet, and all regions with no slope are placed in a third facet?</p>
  
  <p>In the following minimal example, for instance, the target would be to place the rising segments of lines a and b in the positive slope facet, the falling segments of lines a and b in the negative facet, and the segments of a and b with no slope in the no slope facet:</p>
  
  <pre><code>library(ggplot2)
  a.df &lt;- data.frame(matrix(c('A',0,2,'A',1,6,'A',2,6,'A',3,4,'B',0,5,'B',1,4,'B',2,4,'B',3,6),ncol=3,byrow=TRUE))
  
  a.df$X2 &lt;- as.numeric(as.character(a.df$X2))
  a.df$X3 &lt;- as.numeric(as.character(a.df$X3))
  
  ggplot(a.df, aes(x=X2,y=X3,colour=X1)) +
    geom_line()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xulHa.png" alt="enter image description here"></p>
  
  <p>I tried your response MrFlick, but it looks like its placing lines in the positive or negative slope category if their <em>global</em> slope is positive or negative. I'm wondering if it would be possible to place all of the <em>subregions</em> of each line that have positive or negative slope into different facets. Is there a way to modify your code to accomplish this task? I would be grateful for any help you can offer on this question.</p>