Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R will plot but won't draw abline

Tags:

plot

r

> 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.

like image 716
screechOwl Avatar asked Aug 28 '11 16:08

screechOwl


People also ask

How do you Abline a plot in R?

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, …)

How does Abline in R work?

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, …)

What does Abline show in R?

The R function abline() can be used to add vertical, horizontal or regression lines to a graph.

What is the function of Abline H 5?

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.


2 Answers

It should be abline(lm(vixee ~ returnee)) to match the coordinates of the plot.

like image 137
Anatoliy Avatar answered Oct 08 '22 18:10

Anatoliy


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)
like image 41
Ben Bolker Avatar answered Oct 08 '22 18:10

Ben Bolker