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

Bart6114 bartsmeets86 at gmail.com
Thu Mar 15 16:47:21 CET 2012


When plotting a barchart with ggplot it drops the levels of the factor for
which no counts are available.

For example:

ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar()

This shows my problem. Because no counts are available for factorlevel '4',
the label 4 dissapears from the plot. However, I would still like it to show
up, but without a bar (zero observations).

I would like to use this for the presentation of data with a Likert-like

Thanks in advance!

View this message in context: http://r.789695.n4.nabble.com/Ggplot-barchart-drops-factor-levels-how-to-show-them-with-zero-counts-tp4475417p4475417.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list