title: ggplot axis order (factor) changes when using last_plot()
body: <p>I've been able to successfully create a dotpot in ggplot for percentages across gender. But, I want to highlight the significant differences. I thought I could do this with a combination of subsetting and the use of last_plot().</p>
  
  <p>Here’s my data:</p>
  
  <pre><code>require(ggplot2) 
  require(reshape2)
  
  prog &lt;- c("Honors", "Academic", "Social", "Media")
  m &lt;- c(30,35,40,23)
  f &lt;- c(25,40,45,15)
  s &lt;- c(0.7, 0.4, 0.1, 0.03)
  temp &lt;- as.data.frame(cbind(prog, m, f, s), stringsAsFactors=FALSE)
  
  first &lt;- temp[,1:3]
  first.melt &lt;- melt(first, id.vars = 'prog', variable.name = 'Gender', value.name = 'Percent')
  first.melt &lt;- as.data.frame(cbind(first.melt,temp[,4]), , stringsAsFactors=FALSE)
  names(first.melt) &lt;- c("program", "Gender", "Percent", "sig")
  first.melt$program &lt;- as.factor(first.melt$program)
  </code></pre>
  
  <p>Here’s where I reverse order my Program variable, so that when graphed if will be alphabetical from top to bottom.</p>
  
  <pre><code>first.melt[,1] = with(first.melt, factor(first.melt[,1], levels = rev(levels(first.melt[,1]))))
  first.melt$sig &lt;- as.numeric(as.character(first.melt$sig))
  first.melt$Percent &lt;- as.numeric(as.character(first.melt$Percent))
  </code></pre>
  
  <p>Now, I subset...</p>
  
  <pre><code>first.melt.ns &lt;- subset(first.melt,sig &gt; 0.05)
  first.melt.sig &lt;- subset(first.melt,sig &lt;= 0.05)
  
  ggplot(first.melt.ns, aes(program, y=Percent, shape=Gender)) +
    geom_point(size=3) +
    coord_flip() +
    scale_shape_manual(values=c("m"=1, "f"=5)) 
  </code></pre>
  
  <p>The first run at ggplot get’s me my non-significant Program pairs – and it’s in the right order – so, I add my the two new points for male and female (making them solid, to draw attention as a significant pair):</p>
  
  <pre><code>last_plot() + 
    geom_point(data=first.melt.sig, aes(program[Gender=="m"], y=Percent[Gender=="m"]), size=3, shape=19) + 
    geom_point(data=first.melt.sig, aes(program[Gender=="f"], y=Percent[Gender=="f"]),size=4, shape=18) 
  </code></pre>
  
  <p>The points get added just fine – ggplot works. But notice my Program axis – it’s correct, but reversed now.</p>