0

I have a dataframe with the number of male and female per category. I made the following stacked bar plot : enter image description here

Except I cannot manage to add % value for each gender in each barplot's category. Here's my dataset :

Gender <- c("F", "M", "M", "M", "M","F","M","M","F","M")
Cat <- c("Cat1", "Cat1", "Cat2","Cat2","Cat2","Cat1","Cat3","Cat3","Cat2","Cat3")
Count <- c(13, 12, 91, 38, 14, 16, 17, 54, 45, 63)

df <- data.frame(Gender, Cat, Count)

And here's my code :

ggplot(df)+
  aes(x = Cat, fill = Gender)+
  geom_bar(position = "fill")+
  xlab("Cat")+
  ylab("Count")+
  labs(fill = "Gender")+
  scale_y_continuous(labels = scales::percent)

The difference from other questions, is that I don't have a y= defined. So I can't add geom_text(label = y).

Thank you in advance for your help.

Chloé
  • 79
  • 6
  • Related: https://stackoverflow.com/q/12018499/3358272, https://stackoverflow.com/q/6455088/3358272; two-categ-vars https://stackoverflow.com/q/74636143/3358272 – r2evans Mar 02 '23 at 13:29

0 Answers0