-5

I'm having trouble plotting 2 abline()s on a graph of the log10 Brain mass and log10 body mass. I'm following someone else's script but it just doesn't work for me. This is what I have:

enter image description here

This is the graph produced:

enter image description here

Why are the lines off there like that? Are the values I'm getting for the intercept and slope incorrect, or am I using the wrong ones? I've done other examples of this and its worked OK, but I've always ended up using the first model, never the second one so I'm not sure if I'm using the right values.

Thomas
  • 43,637
  • 12
  • 109
  • 140
murph33
  • 13
  • 4
  • 2
    Welcome to SO. Please include a [MCVE](http://stackoverflow.com/help/mcve) as part of your post (i.e., you need to show us what code you've tried or you question will be closed and/or down-voted by other users). [This question on making a great R example will help you as well](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Richard Erickson Jan 21 '16 at 12:50
  • 1
    To clarify my previous comment, please post your code directly to SO, not as an image file. – Richard Erickson Jan 21 '16 at 17:50

2 Answers2

3

If you want to represent a linear regression of the log of the body mass compared to the log of the brain mass, the code is:

model <- lm(log10(brain)~log10(body))

then

abline(model$coefficients[2], model$coefficients[1])

When you don't know which parameter to enter in a function, use the help of that function. For abline(), the first parameter is the slope and the second one is the intercept.

Currently, your model use log10(brain), log10(body) and class.

If you want to assess the quality of your model, look at the residuals.

plot(model)
Thomas
  • 43,637
  • 12
  • 109
  • 140
YCR
  • 3,794
  • 3
  • 25
  • 29
0

You can also just use the result of your lm like this:

    model <- lm(log10(brain)~log10(body))
    plot(log10(brain)~log10(body))
    abline(model,col=2)