title: Dodged barplot with zero counts in ggplot2
body: <p>Suppose we have the following toy data structure:</p>
  
  <pre><code>data &lt;- structure(list(value = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
  2L, 2L, 2L, 3L, 3L, 3L, 3L), class = structure(c(1L, 1L, 1L, 
  2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("A", 
  "B"), class = "factor")), .Names = c("value", "class"), class = "data.frame", row.names = c(NA, 
  -16L))
  </code></pre>
  
  <p>In this data one grouping has the zero count (i.e., there are no counts for class B with value 3):</p>
  
  <pre><code>&gt; library(dplyr)
  &gt; count(data, value, class)
  Source: local data frame [5 x 3]
  Groups: value [?]
  
    value  class     n
    &lt;int&gt; &lt;fctr&gt; &lt;int&gt;
  1     1      A     3
  2     1      B     3
  3     2      A     4
  4     2      B     2
  5     3      A     4
  </code></pre>
  
  <p>Code below plots the barplot (with relative frequencies on the y axis), but I need to display empty space for the zero count. Instead, <code>ggplot2</code> eliminates the bar with zero count. Any suggestion how to include zero counts?</p>
  
  <pre><code>ggplot(data, aes(value, fill = class)) +
  geom_bar(aes(y = ..count../sapply(fill, FUN=function(x) sum(count[fill == x]))), position="dodge")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uUiry.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uUiry.png" alt="enter image description here"></a></p>
  
  <p>This question is related to similar questions (e.g., <a href="https://stackoverflow.com/questions/10326729/dont-drop-zero-count-dodged-barplot">Don't drop zero count</a>) in the past, but the proposed solutions don't work here.</p>