title: r (ggplot2 line graph): changing linetype for errorbars changes them in legend
body: <p>I have a line graph like this one:
  <a href="https://i.stack.imgur.com/2Cpx8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Cpx8.png" alt="graph" /></a></p>
  
  <pre><code>df &lt;- data.frame(x = c(1,1,2,2,1,1,2,2), 
    y = c(1.5,1.9,2.1,1.6,1.4,1.8,2.0,1.7), 
    error = c(0.2), 
    group = c(&quot;g1&quot;,&quot;g2&quot;,&quot;g1&quot;,&quot;g2&quot;,&quot;g3&quot;,&quot;g4&quot;,&quot;g3&quot;,&quot;g4&quot;))
  
  ggplot(df, aes(x = x, y = y, color = group, linetype = group)) + 
    geom_point() + geom_line() + 
    geom_errorbar(aes(ymin = y - error, ymax = y + error),
                  linetype = 1, width = 0.5,                                 
                  position = position_dodge(width = 0.2)) +
    scale_color_manual(values = c(&quot;g1&quot;=&quot;Black&quot;, &quot;g2&quot;=&quot;Grey&quot;, &quot;g3&quot;=&quot;Black&quot;, &quot;g4&quot;=&quot;Grey&quot;)) +
    scale_linetype_manual(values=c(&quot;g1&quot;=1,&quot;g2&quot;=1,&quot;g3&quot;=2,&quot;g4&quot;=2))
  </code></pre>
  <p>I need to make it black and white, so with several groups, I used both <code>color</code> and <code>linetype</code>. When I change line type, I want to have error bars solid although the lines are dotted, so I overrode the linetype for error bars. For some reason, this also changes the legend, so it is no longer clear which line is which.</p>
  <p>I know this somehow depends on the <code>color = group</code> in <code>aes</code>, because when I just had the linetype, the legend was fine. For some reason I just can't find a way to do linetype, color, and solid errorbars at the same time. Anybody know why this is?</p>