[R] ggplot2 percentages of subpopulations

Simon Kiss sjkiss at gmail.com
Tue Sep 10 18:23:26 CEST 2013


Hi there: 
I have a sample data set that looks like below.  The variable 'value' represents the counts of cases in each response category.  And I would like to get the barchart to graph the number of responses as a percentage of each total *subpopulation* (Males compared to Females), rather than as a percentage of *all* the responses.
Can someone provide a suggestion?
Thank you

Yours, Simon Kiss
#Sample Code
sample.dat<-data.frame(response.category=rep(c('A', 'B','C'), 2), value=c(50,25,25, 25,25,25), pop=c(rep('Males', 3), rep('Females', 3)))
#Draw GGPLot
test<-ggplot(sample.dat, aes(x=response.category,y=value, group=pop))
test+geom_bar(stat='identity', position='dodge',aes(fill=pop))



More information about the R-help mailing list