Home > Enterprise >  Bar plot labeling on top of bar
Bar plot labeling on top of bar

Time:12-22

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.

CodePudding user response:

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

CodePudding user response:

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
  • Related