I'm trying to put original counts into a barplot, but it's always messy:
set.seed(123)
c<-c(2, 3.5, 5, 7.9, 8.8, 12.3)
x<-sample(c, 100, replace=T)
barplot(table(x))
text(c, table(x)+2, labels=as.character(table(x)))

Would somebody have some suggestions?
You just need to make sure that ylim is large enough such that none of the text will be placed outside of the plot area, and then you need the positions of the middle of bars and make sure to place the text there.
set.seed(123)
origin <-c(2, 3.5, 5, 7.9, 8.8, 12.3)
x<-sample(origin, 100, replace=T)
b<-barplot(table(x),ylim=c(0,22))
text(x=b, y= table(x)+1, labels=as.character(table(x)))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With