r - How can I label the x-intercept of a vertical abline? - Stack Overflow

admin2025-05-01  1

I have a plot that shows a curve and a couple of ablines:

The plot is created using the curve command. I would like to add the value of the x-intercept below the x-axis . . . is this possible without using a more sophisticated graphing package?

Thanks!!!

I have a plot that shows a curve and a couple of ablines:

The plot is created using the curve command. I would like to add the value of the x-intercept below the x-axis . . . is this possible without using a more sophisticated graphing package?

Thanks!!!

Share Improve this question asked Jan 2 at 19:33 GuyMatzGuyMatz 6996 silver badges10 bronze badges 1
  • 3 Could you edit your question to include sufficient code/data so that it can be reproducible? – jpsmith Commented Jan 2 at 19:36
Add a comment  | 

2 Answers 2

Reset to default 1

In base R you can use mtext to add it in. For the x-axis, side = 1:

x_abline <- -0.25

curve(x ^ 3 - 3 * x, -2, 2)
abline(v = x_abline, col = "red", lty = 2)
mtext(x_abline, side = 1, at = x_abline)

Or axis:

curve(x ^ 3 - 3 * x, -2, 2)
abline(v = x_abline, col = "red", lty = 2)
axis(1, x_abline)

USe axis as shown

plot(1)
abline(v = 1.1)
axis(1, 1.1)

转载请注明原文地址:http://www.anycun.com/QandA/1746100292a91669.html