Reputation: 9793
mydat <- c(rep(4:10, each = 3), rep(1:2, each = 2))
barplot(table(mydat))
abline(v = 3, col = "blue")
This gives me the following plot:
I want a vertical line at x=3
. However, because of the way the x-axis is spaced out, the vertical line doesn't appear to be in the right place. How can I fix this? i.e. I want my plot to look something like this:
Upvotes: 2
Views: 834
Reputation: 76402
To plot a line between the 2nd and the 3rd bars, assign the return value of barplot
and then plot in the mean
value of the 2nd and 3rd of those values.
bp <- as.vector(barplot(table(mydat)))
abline(v = mean(bp[2:3]), col = "blue")
Upvotes: 5