title: R geom_path lines "closing", sometimes. How to keep them "open"?
body: <p>I'm plotting a series of financial projections with ggplot's geom_path(). </p>
  
  <pre><code>ggplot(df,aes(year,pot,color=iRate)) + geom_path() +  theme(legend.position="none") + ylim(0,300000)
  </code></pre>
  
  <p>This is what I have..[sorry it's a link]</p>
  
  <p><img src="https://i.stack.imgur.com/KQsFy.png" alt="problem graph"></p>
  
  <p>..two of the paths hit the right hand edge, year 40, but then nip back to their beginning. One line doesn't. This isn't a problem of axis-display limits, nor of a rogue line in the data frame - if I remove all years &lt; 5 the same thing happens. 
  It may be a just problem of overburdening the plotting device, but it is repeatable.. </p>
  
  <p>There are questions asking how to 'close' a geom_path which don't answer this. How do I ensure the path stays 'open'?</p>
  
  <pre><code>inflation &lt;- seq(1, 1.1, 0.02)
  potGrowth &lt;- seq(1.02, 1.1, 0.02)
  div &lt;- 10000
  initcapital &lt;- 100000
  output &lt;- numeric()
  lifespan &lt;- 40
  delay &lt;- 10
  for(j in 1:length(inflation)){ 
      str &lt;- rep(0,lifespan)
      for(i in delay:lifespan){ str[i] &lt;- floor((inflation[j]^i)*div) }
      for(k in 1:length(potGrowth)){ 
          cap &lt;- initcapital
          for(i in 1:lifespan){  
          cap &lt;- cap-str[i]; cap &lt;- cap*potGrowth[k] 
          output &lt;-  append(output, floor(cap))
          }
      }
  }
  iLen &lt;- length(inflation); gLen &lt;- length(potGrowth)
  simulations &lt;- iLen*gLen    
  df &lt;- data.frame(pot=output, projection=rep(1:simulations,each=lifespan), iRate=rep(inflation,each=lifespan*gLen), gRate=rep(rep(potGrowth,each=lifespan),times=iLen), year=rep(1:lifespan,times=simulations))
  </code></pre>
  
  <p>and here it is solved by inserting group=projection</p>
  
  <p>ggplot(df,aes(year,pot,color=iRate,group=projection)) + geom_path() ...</p>
  
  <p><a href="https://i.stack.imgur.com/tUJgR.png" rel="nofollow noreferrer">non-problem graph</a></p>