First off, I've already read the following thread: ggplot2 - Multi-group histogram with in-group proportions rather than frequency
I followed the ddply suggestion and it didn't seem to work for my data. Logically the code should work perfectly on my dataset and I have no idea what I'm doing wrong.
Overall: I'd like to make a histogram (I'm learning ggplot) that displays the genotype frequency in each of my study groups.
Something like this:
Here's a mock data set that mirrors my own:
df<-data.frame(ID=1:60,
Genotypes=sample(c("CG", "CC", "GG"), 60, replace=T),
Study_Group=sample(c("Control", "Pathology1", "pathology2"), 60, replace=T))
I've tried variants of p + geom_bar(aes(aes(y = ..count../sum(..count..))
but r returns "cannot find 'count' object" or something to that effect.
I also tried:
df.new<-ddply(df,.(Study_Group),summarise,
prop=prop.table(table(df$Genotype)),
Genotype=names(table(df$Genotype)))`
And I believe there was an error with the summarise function, but to be honest, I have no idea what I'm doing.
Is the problem simply my comprehension of the solution or is it something inherently different in my data set?
Thanks for the help.