I have a data set called charities with two treatments (csr), two genders (gender) and performance of the subject (pointspr). I would like to make a histogram with percentage on the y-axis and performance on the x-axis with a facet wrap by treatment and gender. I've provided a minimal example of data.
This code produces histograms by treatment and gender but the percentages are not right. I've seen elsewhere using ..group.. for one two-dimensional variable, but I have two of them: csr and gender.
The graph for csr=0 and gender=1 should have 66.7% for pointspr=10 but the graph produced with this code has the percentage at around 15%. Thanks for any help.
library(ggplot)
charities <- csr=c(0,0,0,0,0,0,1,1,1,1,1,1),
gender=c(1,1,1,2,2,2,1,1,1,2,2,2),
pointspr=c(10,5,10,15,12,12,2,2,5,1,1,4)
ggplot(charities, aes(x = factor(pointspr))) +
geom_bar(binwidth=1, aes(y = (..count..)/sum(..count..)), fill = 'lightblue') +
scale_y_continuous(labels=percent) +
facet_wrap(csr ~ gender) +
labs(x = 'Number of correct answers under piece rate incentive', y = 'Percentage') +
theme_minimal()