How to put values over bars in barplot in R [closed]

This question is related to my previous question. I would like to put values over bars in barplot. I am beginner in plotting in R.

Answer

To add text to a plot, just use the text command. From @chl’s answer to your previous question:

##Create data
x = replicate(2, sample(letters[1:2], 100, rep=T))
apply(x, 2, table)

##Create plot
barplot(matrix(c(5, 3, 8, 9), nr=2), beside=TRUE, 
        col=c("aquamarine3", "coral"), 
        names.arg=LETTERS[1:2], 
        ylim=range(0,12)))

##Add text at coordinates: x=2, y=6
##Use trial and error to place them 
text(2, 6, "A label")
text(5, 10, "Another label")

alt text

Attribution
Source : Link , Question Author : Skarab , Answer Author : Community

Leave a Comment