0

How do I adjust the position in geom_text to distribute the column labels over each of their respective columns, currently they are all aligned on top of each other (see picture)enter image description here

ggplot(ESCd, aes(factor(S),fill = ESC9)) + 
  geom_bar(stat="count", position = "dodge")+
  geom_text(stat='count', aes(label=..count..), vjust=-1, position = "identity")
James
  • 45
  • 5

1 Answers1

1

We could use position = position_dodge():

Here is an example with the built in diamonds dataframe:

library(ggplot2)
ggplot(diamonds, aes(factor(cut),fill = factor(color))) + 
  geom_bar(stat="count", position = "dodge")+
  geom_text(stat='count', aes(label=..count..), position = position_dodge(width = 0.9), 
            vjust = -0.25, color = "black", size = 3)

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66