I want to draw a vertical line at specific positions of the x-axis, but the x-positions of the lines aren't correct. How can I solve this ?
x <- c(0,0,0,4,5,6)
barplot(x, names.arg=1:length(x))
abline(v=1:length(x), col="red")
abline(v=c(5.5), col="blue")
You have to save the result of barplot
. Then use those values to plot the vertical lines.
x <- c(0,0,0,4,5,6)
bp <- barplot(x, names.arg = seq_along(x))
abline(v = bp, col = "red")
abline(v = 5.5, col = "blue")
Note that the blue line was plotted twice and therefore became violet. So remove the value 5.5
from the first call to abline
.
bp <- barplot(x, names.arg = seq_along(x))
abline(v = bp[bp != 5.5], col = "red")
abline(v = 5.5, col = "blue")
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