misran
misran

Reputation: 37

Bar plot labeling on top of bar

How to label the bar plot bars with the label text vertically aligned: Bar Label.

I am using the basic function barplot and text, but unable to achieve this. Request help on this. Thank you.

Upvotes: 3

Views: 171

Answers (2)

Kylian
Kylian

Reputation: 329

Some reproducable code would be helpful to give you a more concrete/helpful answers. However, I believe you are looking for the geom_text with the vjust input. You can play around to find exactly what you like. vjust means something like vertical adjustment. Try a vjust of -0.5, 0.5 or whatever to see what works best in your case.

geom_text(aes(label = n), vjust = -0.5, size = 5)  ## inserts number on top of a bar

Upvotes: 0

Tur
Tur

Reputation: 614

With basic R, use text:

x = rnorm(10, 5, 2)
(d <- barplot(x, ylim = c(0, max(x)+1)))
text(x = d, y = x,
     label = round(x, 2), pos = 3, cex = 0.8, col = "red", srt=90, offset = 1)

enter image description here

Upvotes: 1

Related Questions