title: ggplot2: Shape, Color and Linestyle into one legend
body: <p>I want to create a ggplot2-diagram with lines and bars, visualizing different values y and ybar. The lines are overlayed with dots also based on values y. There should be 2 legends in the end, one for the line (+dot) diagram, comprising colours, shapes and linestyle, and one for the bars, comprising the fill colour. The linestyles, dot-shapes and colours are changed accordingly to the variable type (y1 or y2). This works well, until I manually want to set the legend name and the item labels:</p>
  
  <p>Minimal code for dataframe initialisation:</p>
  
  <pre><code>library(ggplot2)
  library(reshape)
  df = data.frame(c(10,20,40),c(0.1,0.2,0.3),c(0.1,0.4,0.5),c(0.05,0.1,0.2),c(0,0.2,0.4))
  names(df)[1]="classes"
  names(df)[2]="y1"
  names(df)[3]="y2"
  names(df)[4]="bary1"
  names(df)[5]="bary2"
  df$classes &lt;- factor(df$classes,levels=c(10,20,40), labels=c("10m","20m","40m"))
  </code></pre>
  
  <p>Minimal code for creating point,line and bar diagram:</p>
  
  <pre><code>dfMelted &lt;- melt(df)
  diagram &lt;- ggplot()
  diagram &lt;- diagram + theme_bw(base_size=16)
  diagram &lt;- diagram + geom_bar(data=subset(dfMelted,variable=="bary1" | variable=="bary2"), aes(x=factor(classes),y=value, fill=variable),stat="identity",position="dodge")
  diagram &lt;- diagram + geom_point(data=subset(dfMelted,variable=="y1" | variable=="y2"), size=4, aes(x=factor(classes),y=value, colour=variable, shape=variable)) 
  diagram &lt;- diagram + geom_line(data=subset(dfMelted,variable=="y1" | variable=="y2"), aes(x=factor(classes),y=value, group=variable, colour=variable, linetype=variable))
  </code></pre>
  
  <p>Preliminary result:</p>
  
  <p><img src="https://i.stack.imgur.com/3GO1n.png" alt="Looks good so far"></p>
  
  <p>Setting legend name / item labels via the following code:</p>
  
  <pre><code>diagram + scale_colour_brewer(name="Line Legend",labels=c("Foo","Bar")) + scale_fill_brewer(name="Bar Legend",labels=c("Foo Bar","Bar Bar"))
  </code></pre>
  
  <p>produces unwanted result:</p>
  
  <p><img src="https://i.stack.imgur.com/OYQLy.png" alt="Problem: legend split into color, linestyle, shape"></p>
  
  <p>In the final result, the two desired legend are split into three. There is no more legend, in which colours, linestyle and point shape are unified. Why's that? How to solve this? Also using scale_colour_manual() and scale_shape_manual() produces a similar result.</p>
  
  <p>I browsed through related posts and found no answer to this complex situation.</p>