Don't drop zero count: dodged barplot

ggplot2, r

Solution

The only way I know of is to pre-compute the counts and add a dummy row:

dat <- rbind(ddply(mtcars2,.(type,group),summarise,count = length(group)),c(8,4,NA))

ggplot(dat,aes(x = type,y = count,fill = group)) + 
    geom_bar(colour = "black",position = "dodge",stat = "identity")

I thought that using `stat_bin(drop = FALSE,geom = "bar",...)` instead would work, but apparently it does not.

Problem

I am making a dodged barplot in ggplot2 and one grouping has a zero count that I want to display. I remembered seeing this on HERE a while back and figured the `scale_x_discrete(drop=F)` would work. It does not appear to work with dodged bars. How can I make the zero counts show? For instance, (code below) in the plot below, type8~group4 has no examples. I would still like the plot to display the empty space for the zero count instead of eliminating the bar. How can I do this? ``` mtcars2 <- data.frame(type=factor(mtcars$cyl), group=factor(mtcars$gear)) m2 <- ggplot(mtcars2, aes(x=type , fill=group)) p2 <- m2 + geom_bar(colour="black", position="dodge") + scale_x_discrete(drop=F) p2 ```

Original source