> head(returnee)
[1] 1.3936536 -0.6730667 2.3584725 2.3477308 3.2841443 1.3168157
> head(vixee)
[1] 14.75 15.45 17.59 17.74 17.75 18.35
> class(returnee)
[1] "numeric"
> class(vixee)
[1] "numeric"
> plot(returnee, vixee)
> abline(lm(returnee ~ vixee))
When I run this, it gives the plot, but there is no abline. Any suggestions? Thanks.
The abline() function in R can be used to add one or more straight lines to a plot in R. This function uses the following syntax: abline(a=NULL, b=NULL, h=NULL, v=NULL, …)
abline() function in R Language is used to add one or more straight lines to a graph. The abline() function can be used to add vertical, horizontal or regression lines to plot. Syntax: abline(a=NULL, b=NULL, h=NULL, v=NULL, …)
The R function abline() can be used to add vertical, horizontal or regression lines to a graph.
The h= and v= forms draw horizontal and vertical lines at the specified coordinates. The coef form specifies the line by a vector containing the slope and intercept. reg is a regression object with a coef method.
It should be abline(lm(vixee ~ returnee))
to match the coordinates of the plot.
In contrast to @AK, I was going to say you had your plot backwards. One or the other ... if the regression is the way you want it (i.e. y~x
) then try either
plot(vixee ~ returnee) ## formula interface, y~x
or
plot(returnee,vixee) ## standard interface, (x,y)
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