1
votes

I started "coding" in R and work on the boston dataset. My task is now to show the relationship between housing values medv and crime rates crim in a scatter plot and label the x-axis (cr) and y-axis (mhv) and just add a main title (SÜ of hv and cr". This worked all fine so far. Now I only have a seemingly minor problem. I also have to add a "linear fit to the plot" - linear regression line and that works fine I think too. But just basic how do I add a colour to this? E.G. blue/red/green whatever, to this line?

 plot(Boston$crim, Boston$medv, main = "SÜ of hv and cr",
   xlab = "cr", ylab = "mhv")
 m <- lm(Boston$medv ~ Boston$crim)
 abline(m)
1

1 Answers

2
votes

abline(m, col = "red") will do. Also, lty will change line type and lwd will change width of line