title: ggplot2: how to adjust line types + order in legend?
body: <p>I would like to adjust the linetypes in the following ggplot. I thus introduce another column in the data.frame df to represent the line type, but once I convert it to a factor the linetype instead of "method" appears in the legend... (see trial 3). </p>
  
  <p>How can I get "method" in the legend? In the end I would like to be able to </p>
  
  <ol>
  <li>freely choose the linetype, </li>
  <li>freely choose the order in which these linetypes appear in the legend, and </li>
  <li>have the corresponding "method" shown as legend text.</li>
  </ol>
  
  <p>Here are my attempts:</p>
  
  <pre><code>require(ggplot2)
  set.seed(1)
  df &lt;- data.frame(x=c(1:4, 2:5),
                   method=rep(c("a", "b"), each=4),
                   lt=rep(c(5,3), each=4),
                   value=rep(c(0,1), each=4)+runif(8))
  
  ## trial 1:
  ggplot(df, aes(x=x, y=value)) + 
     geom_point() + 
     geom_line(aes(group=method, linetype=method)) 
  # fine, but not the linetypes I would like to have
  
  ## trial 2:
  ggplot(df, aes(x=x, y=value)) + 
     geom_point() + 
     geom_line(aes(group=method, linetype=lt)) 
  # correct linetypes, but no legend
  
  ## trial 3:
  ggplot(df, aes(x=x, y=value)) + 
     geom_point() + 
     geom_line(aes(group=method, linetype=as.factor(lt))) 
  # legend, but not the correct one (I would like to have the "group"ing 
  # variable "method" in the legend as in trial 1)
  </code></pre>