Remove unused factor levels from a ggplot bar plot
===

I want to do the opposite of [this question](http://stackoverflow.com/questions/10834382/ggplot2-keep-unused-levels-barplot), and sort of the opposite of [this question](http://stackoverflow.com/questions/10002627/ggplot2-0-9-0-automatically-dropping-unused-factor-levels-from-plot-legend), though that's about legends, not the plot itself.

The other SO questions seem to be asking about how to *keep* unused factor levels. I'd actually like mine removed. I have several name variables and several columns (wide format) of variable attributes that I'm using to create numerous bar plots. Here's a reproducible example:

    library(ggplot2)
    df <- data.frame(name=c("A","B","C"), var1=c(1,NA,2),var2=c(3,4,5))
    ggplot(df, aes(x=name,y=var1)) + geom_bar()

I get this:

![enter image description here][1]

I'd like only the names that have corresponding var<sub>n</sub>'s show up in my bar plot (as in, there would be no empty space for B).

Reusing the base plot code will be quite easy if I can simply change my output file name and `y=var` bit. I'd like not have to subset my data frame just to use droplevels on the result for each plot if possible!


  [1]: http://i.stack.imgur.com/iH15f.png