Reputation: 811
I have a plot of a quadratic function using the following R code. I wonder if there's a way to mark the value of axis of symmetry on the x-axis (which is the value of vertical line).
b1 = 2
b2 = -1
c =100
x = -10:10
f <- function(x) {
return(c + b1 * x + b2 * x^2)
}
plot(x, f(x))
abline(v =-b1/(2*b2), col = "red", lwd = 1, lty = 1)
Upvotes: 0
Views: 89
Reputation: 41377
Another option is using mtext
with as.character
to get the value like this:
b1 = 2
b2 = -1
c =100
x = -10:10
f <- function(x) {
return(c + b1 * x + b2 * x^2)
}
plot(x, f(x))
abline(v =-b1/(2*b2), col = "red", lwd = 1, lty = 1)
mtext(as.character(-b1/(2*b2)),1,line=1,at=-b1/(2*b2),col="red")
Created on 2022-10-30 with reprex v2.0.2
Upvotes: 1