title: ggplot2 0.9.0 automatically dropping unused factor levels from plot legend?
body: <p>I recently upgraded to ggplot2 0.9.0 from version 0.8.9, and now I'm getting that my plot legends only show the factor levels used in the plot (it omits the unused ones). Before it'd include all factor levels in the legend. I'm running Windows 7 and R 2.15.0 (2.14.2 before today).</p>
  <p>Is anyone else finding this too? Is there a way I can get the unused factor levels to display in my plot legend?</p>
  <pre><code>library(ggplot2)
  
  df &lt;- data.frame(fruit = rep(c(&quot;apple&quot;, &quot;orange&quot;), times=11), 
                   year = 1990:2011, 
                   qty = rnorm(22, 100, 20))
  
  # This plot only gives &quot;apple&quot; in the legend now.
  # Before, I used to get both &quot;apple&quot; and &quot;orange&quot;. 
  qplot(year, qty, data = subset(df, fruit==&quot;apple&quot;), colour = fruit) 
  </code></pre>
  <p>The qplot() used to give me both &quot;apple&quot; and &quot;orange&quot; in the legend (even though there were only points for &quot;apple&quot;). Now I only get &quot;apple&quot; in the legend.</p>
  <p>Reason this came up - I am making many plots of subsets of a data set and I want the legends standardized across plots (normally I'd appreciate the unused levels being automatically dropped and not having to type droplevels(), but this is the one case I want those unused levels). Apologies if this is a question local to my computer only.</p>
  <hr />
  <p><strong>Edit</strong>: Note that as of R 4.0.0, the above code no longer produces a <code>df$fruit</code> as a factor, which changes the behavior of <code>ggplot</code> in the question and answers below. To reproduce use:</p>
  <pre><code>df &lt;- data.frame(
    fruit = factor(rep(c(&quot;apple&quot;, &quot;orange&quot;), times=11)), 
    year = 1990:2011, 
    qty = rnorm(22, 100, 20)
  )
  </code></pre>