0

I want to create a bar-plot with geom_text(). Above every bar should be the count of the variable. But in this case the position of the text is in the middle of the barplot. Can someone help me to solve this problem?

new.data <- diamonds[ which( diamonds$clarity =="VS1" | diamonds$clarity =="VS2") , ]

ggplot(data=new.data, aes(x=clarity, fill=cut)) +
  geom_bar(position = "dodge",stat = "count") +
  geom_text(stat='count', aes(label=..count..), vjust=-1)

enter image description here

TobKel
  • 1,293
  • 8
  • 20

1 Answers1

1

add the position argument like mentioned in the similar question here

new.data <- diamonds[ which( diamonds$clarity =="VS1" | diamonds$clarity =="VS2") , ]

ggplot(data=new.data, aes(x=clarity, fill=cut)) +
  geom_bar(position = "dodge",stat = "count") +
  geom_text(stat='count', aes(label=..count..), vjust=-1,
            position = position_dodge(width = 0.9))

output:

plot

like mentioned by TobKel in the commentary, it is possible to variate with the width.

mischva11
  • 2,811
  • 3
  • 18
  • 34