percentage on y lab in a faceted ggplot barchart?

Here is a within ggplot method, using ..count.. and ..PANEL..:

ggplot(test, aes(test2)) + 
    geom_bar(aes(y = (..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..])) + 
    facet_grid(~test1)

As this is computed on the fly, it should be robust to changes to plot parameters.

Leave a Comment