1

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

enter image description here

Tung
  • 26,371
  • 7
  • 91
  • 115
  • 1
    https://stackoverflow.com/questions/29869862/how-to-add-percentage-or-count-labels-above-percentage-bar-plot – Tung Oct 24 '18 at 18:05
  • I don't think this is exactly a duplicate. You need to have a data.frame with the total number for male and female. Then add a `geom_text` line and set the `aes(text)` to the count of the participants. If you post your data, I can show you. – Ben G Oct 24 '18 at 19:12
  • Thank you Ben, but I've figured it out. – Nadia Maalin Oct 24 '18 at 19:32

0 Answers0