0

Here I am trying to able to plot the graph with the below two lines of code.

ggplot(Melvyl,aes(x=Type.of.Customer)) + 
  geom_histogram(stat="count")

This is the graph i am getting

But I want data labels or the count on each of the category, trying the below code but its not working. can you please help me out! Thank you

ggplot(Melvyl,aes(x=Type.of.Customer)) + 
  geom_histogram(stat="count")+  stat_bin(binwidth=1, geom="text", aes(label=..count..), vjust=-1.5) 
stefan
  • 90,330
  • 6
  • 25
  • 51
  • Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Aug 14 '22 at 20:51

1 Answers1

0

Instead of using geom_histogram you could go on with geom_bar. To add your labels use geom_text with stat="count".

Using mtcars as example data:

library(ggplot2)

ggplot(mtcars, aes(x=cyl)) + 
  geom_bar() +
  geom_text(aes(label=..count..), stat = "count", vjust=-1.5) 

stefan
  • 90,330
  • 6
  • 25
  • 51