title: How can I define line plotting order in ggplot2 for grouped lines?
body: <p>I have a dataframe similar to the following:</p>
  
  <pre><code>set.seed(1)
  df = data.frame(group = sort(rep(1:15,5)), x = rep(1:5,15), 
  y = c(runif(25,-1,1), runif(25, -.5,.5),runif(25,-1,1)),
  flag = c(rep('false', 25), rep('true',25),rep('false', 25)))
  </code></pre>
  
  <p>where x and y are coordinates for plotting, group is an identifier for distinct lines, and flag is a boolean indicating a special subset of the line groups.  I would like to use ggplot to plot these lines so the lines with <code>flag = 'true'</code> appear on top.  However, the plotting order seems to be determined only by the group name.  In my example df, since the values with <code>flag = 'true'</code> correspond to groups 6-10, they are plotted above groups 1-5 but below groups 11-15. This happens even if I try to use the <code>order</code> aesthetic in the following manner:</p>
  
  <pre><code>ggplot(data = df, aes(x = x, y = y, colour = flag,
  group = group, order = flag)) + geom_line(size = 3)
  </code></pre>
  
  <p>I am able to get the plotting order I desire if I rename the group labels (for example if the examples with <code>flag = true</code> are groups 11-15 instead of 6-10) but I would assume there is a better way to do this.  Is there some way to override the ordering by group name?</p>