title: When filtering with dplyr in R, why do filtered out levels of a variable remain in filtered data?
body: <p>I'm trying to filter out a bunch of data using the <code>filter</code> command from the <code>dplyr</code> package. Everything appears to be going exactly as I would hope, but when I try to draw some charts off of the new filtered data, all of the levels that I filtered out are showing up (albeit with no values). But the fact that they are there is still throwing off my horizontal axis.</p>
  
  <p>So two questions:</p>
  
  <p>1) Why are these filtered levels still in the data?</p>
  
  <p>2) How do I filter to make these no longer present?</p>
  
  <p>Here is a small example you can run to see what I am talking about:</p>
  
  <pre><code>library(dplyr)
  library(ggvis)
  
  # small example frame
  data &lt;- data.frame(
    x = c(1:10),
    y = rep(c("yes", "no"), 5)
  )
  
  # filtering to only include data with "yes" in y variable
  new_data &lt;- data %&gt;%
    filter(y == "yes")
  
  levels(new_data) ## Why is "no" showing up as a level for this if I've filtered that out?
  
  # Illustration of the filtered values still showing up on axis
  new_data %&gt;%
    ggvis(~y, ~x) %&gt;%
    layer_bars()
  </code></pre>
  
  <p>Thanks for any help.</p>