# How do I include regression lines for all 6 characteristics of a variable

For my task I have to draw a scatterplot. Which I have done here:

``````plot(airbnb\$distance_center,airbnb\$price,pch=13,xlab="distance_center",ylab="price",bty="n")
``````

Then I have to include regression lines that show the correlation of price and distance_center for all 6 characteristics of my variable "number_of_people"

Here my model:

``````mod<-lm(price~number_people+distance_center)
``````

My try:

``````abline(mod\$coeff+mod\$coeff,mod\$coeff,col=2,lwd=2)

abline(mod\$coeff+mod\$coeff,mod\$coeff,col=2,lwd=2)

abline(mod\$coeff+mod\$coeff,mod\$coeff,col=2,lwd=2)
``````

it shows 3 increasing ablines but I don't quite understand this way, I am not sure how to include all 6 as even if I increase it only shows 3. And I don't think this is right, has anyone a right idea?

First, I assume that by characteristics of the number_people variable you mean the possible values, such as 1 to 6.

Second, mod\$coeff is the intercept of the estimated equation and mod\$coeff and mod\$coeff are the slope coefficients for the number_people and distance_center variables, respectively. The slope for all of your ablines should be mod\$coeff, not mod\$coeff

Third, the intercepts of the ablines are the intercept of the estimated equation mod\$ plus the effects of different values of number_people. You need to multiply each possible value of number_people by the slope coefficient for number_people, mod\$coeff. Assuming the six possible values are 1 to 6:

``````abline(mod\$coeff + mod\$coeff*1, mod\$coeff, col = 2, lwd = 2)
abline(mod\$coeff + mod\$coeff*2, mod\$coeff, col = 2, lwd = 2)
abline(mod\$coeff + mod\$coeff*3, mod\$coeff, col = 2, lwd = 2)
abline(mod\$coeff + mod\$coeff*4, mod\$coeff, col = 2, lwd = 2)
abline(mod\$coeff + mod\$coeff*5, mod\$coeff, col = 2, lwd = 2)
abline(mod\$coeff + mod\$coeff*6, mod\$coeff, col = 2, lwd = 2)
``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.