title: ggplot2 keep unused levels barplot
body: <p>I want to plot unused levels (that is, levels where the count is 0) in my bar-plot, however, unused levels are dropped and I cannot figure out how to keep them</p>
  
  <pre><code>df &lt;- data.frame(type=c("A", "A", "A", "B", "B"), group=rep("group1", 5))
  df$type &lt;- factor(df$type, levels=c("A","B", "C"))
  
  ggplot(df, aes(x=group, fill=type)) + geom_bar()
  </code></pre>
  
  <p>In the above example, I want to see C plotted with a count of 0, but it is completely absent...</p>
  
  <p>Thanks for any help
  Ulrik </p>
  
  <p>Edit:</p>
  
  <p>This does what I want</p>
  
  <pre><code>df &lt;- data.frame(type=c("A", "A", "A", "B", "B"), group=rep("group1", 5))
  df1 &lt;- data.frame(type=c("A", "A", "A", "B", "B", "A", "A", "C", "B", "B"), group=c(rep("group1", 5),rep("group2", 5)))
  
  df$type &lt;- factor(df$type, levels=c("A","B", "C"))
  df1$type &lt;- factor(df1$type, levels=c("A","B", "C"))
  df &lt;- data.frame(table(df))
  
  df1 &lt;- data.frame(table(df1))
  
  ggplot(df, aes(x=group, y=Freq, fill=type)) + geom_bar(position="dodge")
  ggplot(df1, aes(x=group, y=Freq, fill=type)) + geom_bar(position="dodge")
  </code></pre>
  
  <p>Guess the solution is to calculate the frequencies using table() and then plot</p>