Regarding adding bar labels on top of each bar in ggplot() using geom_text()

ggplot2
rstudio

#1


#2

Hi @amodaks try the code given below…

ggplot(iris) + aes(Species) + geom_bar() + 
  geom_text(stat = "count", aes(label = ..count.., y = ..count..))

#3

Thanks sir it worked…now…may I just know that why do we have to write. stat = “count” inside geom_text. geom_text(stat = “count”, aes(label = …count…,
Thanks,

Amod ShirkeCapture


#4

hello pjoshi, I want to add bar values on top of each stacked bar in the bar plot with geom_text() of titanic dataset…
My x variable is ‘Sex’ and have filled it with the variable ‘Survived’
here is my code:
ggplot(titanic) + aes(x= Sex, fill = Survived) + geom_bar()

output:
Rplot