I have the following data frame
z x y
1 1 a
2 2 a
3 1 a
4 2 a
5 1 b
6 9 b
7 9 b
8 8 b
9 7 b
when I do
p = ggplot(z,aes(x,group=y)) + geom_histogram(aes(y = ..density..,group=y)) + facet_grid(y ~ .)
p
I get the faceted plots, but not with the percentages on the y-axis for each symbol within z$y.
Basically, I want a histogram chart, but with the percentages that show the frequency distribution within each value of z$y i.e. a,b.
In this case, under ‘a’, 50% is 1 and 50% is 2, and under ‘b’, 20% is 1, 40% is 9, 20% is 7 and 20% is 8. I want this charted as histograms using faceting.
That is not a histogram (there is no density estimation), but a bar chart.
Note: In more recent versions of ggplot2 we would use
scale_y_continuous(labels = percent_format())instead, and make sure to load the scales package.