I want to create a histogram that presents the proportion of females (y axis) for each age group (x-axis). I want to have two bars for each age group that represent females with disease "N" and without disease "N".
Data:
Other posts related to this topic that I have reviewed:
r percentage by bin in histogram ggplot
Barplots with multiple factor groupings and mean of variable across those factors
Code I have tried:
ggplot(N_group, aes(x=Age_2, fill=Sex))+
geom_bar(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..]), position="dodge" ) +
geom_text(aes( y=..count../tapply(..count.., ..x.. ,sum)[..x..],
label=scales::percent(..count../tapply(..count.., ..x.. ,sum)[..x..]) ),
stat="count", position=position_dodge(0.9), vjust=-0.5)
This compares males and females that have disease "N".