I am trying to add count labels to my bar chart which is a simple frequency chart of the number of males and females in our study. I have tried + stat_count() and get the error - Error: stat_count requires the following missing aesthetics: x. I have also tried + geom_label(stat = "count"). Nothing seems to work. I can do this easily using excel, but I would like to do all my plots using R.
Does anyone have a simple solution for this?
My code:
`# Count of M vs F
sexfreq <- ggplot(data = BodyComp) +
geom_bar(mapping = aes(SEX), width = .5, fill = "gray30") +
ggtitle ("Number of male and female participants") +
labs( x = "Sex", y = "Number of participants") +
theme_minimal() +
scale_fill_grey()
sexfreq
`
It produces this: My plot without bar labels