[R] Ggplot barchart drops factor levels: how to show them with zero counts?

Ben Bolker bbolker at gmail.com
Fri Mar 16 14:30:36 CET 2012


R. Michael Weylandt <michael.weylandt <at> gmail.com> writes:

> 
> I can reproduce the OP's problem with ggplot 0.9.0 but I don't know
> how to solve it: perhaps you should take this to the ggplot2 mailing
> list: https://groups.google.com/group/ggplot2?pli=1
> 
> Michael
> 
> On Fri, Mar 16, 2012 at 4:17 AM, Bart6114 <bartsmeets86 <at> gmail.com> wrote:
> > To visualize my problem a little; see this screenshot
> > http://i40.tinypic.com/fodsm0.png http://i40.tinypic.com/fodsm0.png .
> >
> > So I would like factor level 4 to show up but without a bar (zero counts).
> >
> > Thanks
> >

  Supposedly 

ggplot(subset(mtcars,cyl!=4),aes(cyl))+stat_bin(drop=FALSE)

*should* work (see ?stat_bin) -- maybe a bug?  I would second the
advice to put this on the ggplot mailing list ...



More information about the R-help mailing list