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

2012-03-16 Thread Ben Bolker
R. Michael Weylandt 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

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

2012-03-16 Thread Helios de Rosario
You can tell that levels must not be dropped with scale_x_discrete(): library(ggplot2) mtcars$cyl<-factor(mtcars$cyl) plot1 <- ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar() plot1 + scale_x_discrete(drop=FALSE) Or explicitly set the values you want in the x axis with the argument "limits":

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

2012-03-16 Thread R. Michael Weylandt
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 wrote: > To visualize my problem a little; see this scree

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

2012-03-16 Thread Bart6114
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 -- View this message in context: http://r.789695.n4.nabble.com/Ggplot-barchart-drops-fac

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

2012-03-15 Thread Bart6114
Thanks for the fast reply. I'm using ggplot2 (it was a typo in my code example). However, using exactly the same example as I mentioned before, it only shows the bars for cyl=6&8. How can the behaviour be different on differing machines? I just checked for updates and I have the latest ggplot2.

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

2012-03-15 Thread Sarah Goslee
One possibility: update to ggplot2. The original ggplot isn't even on CRAN any longer. When I tried your example with ggplot2, the empty bar for 4 was plotted as you'd expect. Thanks for the small reproducible example. Sarah On Thu, Mar 15, 2012 at 11:47 AM, Bart6114 wrote: > Hello, > > When p

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

2012-03-15 Thread Bart6114
Hello, When plotting a barchart with ggplot it drops the levels of the factor for which no counts are available. For example: library(ggplot) mtcars$cyl<-factor(mtcars$cyl) ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar() levels(mtcars[!mtcars$cyl==4,]) This shows my problem. Because no cou