doing facets in ggplot I would often like the percentage to be used instead of counts.
e.g.
test1 <- sample(letters[1:2], 100, replace=T)
test2 &
A very simple way:
ggplot(test, aes(test2)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
facet_grid(~test1)
So I only changed the parameter of geom_bar to aes(y = (..count..)/sum(..count..)).
After setting ylab to NULL and specifying the formatter, you could get:
ggplot(test, aes(test2)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
facet_grid(~test1) +
scale_y_continuous('', formatter="percent")
Update
Note that while formatter = "percent") works for ggplot2 version 0.8.9, in 0.9.0 you'd want something like scale_y_continuous(labels = percent_format()).
