title: R ggplot2 geom_area() colors beneath a single line produce strange connections
body: <h1>Description of the problem with an example</h1>
  <p>Imagine I have this data.frame</p>
  <pre><code>x &lt;- seq(1, 100) # the indexes
  y &lt;- c(seq(1, 25), seq(25, 1), seq(1, 25), seq(25, 1)) # the y values
  group_nb &lt;- c(replicate(25, &quot;group1&quot;), replicate(25, &quot;group2&quot;), replicate(25, &quot;group1&quot;), replicate(25, &quot;group2&quot;)) # group info
  df &lt;- data.frame(x, y, group_nb)
  </code></pre>
  <p>That looks like this:</p>
  <pre><code>x       y        group_nb
  -------------------------
  1       1        group1
  2       2        group1
  3       3        group1
  </code></pre>
  <p>My <em><strong>first goal</strong></em> is to plot the line <code>y</code> in function of <code>x</code> with color depending on the <code>group_nb</code>.
  My <em><strong>second goal</strong></em> is to shade the area beneath this line correctly.</p>
  <p>The problems I am facing are that I have unwanted connections between points in group1 at index (1:25) and point in group1 at index (50:75).</p>
  <h1>1) Color the line in function of <code>group_nb</code></h1>
  <p>To color the same line using ggplot, I first tested this:</p>
  <pre><code>ggplot(df, aes(x = x, y = y, group=group_nb, color=group_nb)) + 
    geom_line() 
  </code></pre>
  <p>which gave this plot:</p>
  <p><a href="https://i.stack.imgur.com/aFqoP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aFqoP.png" alt="WRONG:geom_line using group colors" /></a></p>
  <p>As you can see, there are unwanted connections between points from the same groups.</p>
  <p>So I found that by adding <code>aes(group=1)</code> to <code>geom_line()</code> parameters corrected the problem of the unwanted connections between groups.</p>
  <pre><code>ggplot(df, aes(x = x, y = y, group=group_nb, color=group_nb)) + 
    geom_line(aes(group = 1) 
  </code></pre>
  <p>This gave the plot that I wanted:</p>
  <p><a href="https://i.stack.imgur.com/3O6xI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3O6xI.png" alt="CORRECT:geom_line using group colors" /></a></p>
  <h1>2) Color beneath the line in function of <code>group_nb</code></h1>
  <p>Now I want to be able to shade the area beneath the line with the same colors.
  Up until now I have this:</p>
  <pre><code>ggplot(df, aes(x = x, y = y, group=group_nb, color=group_nb, fill=group_nb)) + 
    geom_line(aes(group=1)) +
    geom_area()
  </code></pre>
  <p>Which makes the same unwanted connections.  We can see that the region with indexes (50:75) is hidden by the shading of group2 but should be the color of group1.</p>
  <p><a href="https://i.stack.imgur.com/ew0g3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ew0g3.png" alt="WRONG:geom_area using group colors" /></a></p>
  <p>I tried adding <code>aes(group=1)</code> to <code>geom_area()</code> but it gave me the error <code>Erreur : Aesthetics can not vary with a ribbon</code></p>
  <p>So my <strong>questions</strong> are</p>
  <ul>
  <li>How can I solve this?</li>
  <li>Why adding aes(group = 1) in <code>geom_line()</code> helps.</li>
  </ul>
  <p>Thank you for your help.</p>