1

I have 3 models, all of which are significant and I want to create a linear graph with my data. This is what I have so far:

>morpho<-read.table("C:\\Users\\Jess\\Dropbox\\Monochamus\\Morphometrics.csv",header=T,sep=",") > attach(morpho) > wtpro<-lm(weight~pronotum) > plot(weight,pronotum) > abline(wtpro) 

I have tried entering the abline as:

abline(lm(weight~pronotum)) 

I can't figure out what I'm doing wrong. I want to add my equation, I have all of my coefficients but can't get past the line...I have even started over thinking maybe I messed up along the way and it still will not work. Is there a separate package that I am missing?

1
  • you should accept an answer if you found one (or both) helpful. Commented Dec 20, 2012 at 9:52

2 Answers 2

3

Try:

abline(coef(lm(weight~pronotum)) # works if dataframe is attached. 

I try to avoid attach(). It creates all sorts of anomalies that increase as you do more regression work. Better would be:

wtpro<-lm(weight~pronotum, data= morpho) with( morpho , plot(weight,pronotum) ) abline( coef(wtpro) ) 
Sign up to request clarification or add additional context in comments.

Comments

2

Plot is in the format plot(x, y, ...) and it looks like you've ordered your dependent variable first. Easy mistake to make.

For example:

Set up some data

y <- rnorm(10) x <- rnorm(10) + 5 

A plot with the dependent variable placed on the x axis will not display the regression line as it's outside of the visible plane.

plot(y,x) abline(lm(y~x), col='red', main='Check the axis labels') 

Flip the variables in the plot command. Now it will be visible.

plot(x,y) abline(lm(y~x), col='red', main='Check the axis labels') 

2 Comments

Thank you so much! I kept my model as is wtpro<-lm(weight~pronotum) but changed my plot to plot(pronotum,weight) and added abline(wtpro). I really appreciate it....this has been frustrating me.
Done the same before myself. So you know, if you consider the answer satisfactory, to let people know the question is answered, you should click the 'tick' mark next to my answer. That way it gets recorded as done. @user1896450

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.