Tuesday, July 22, 2014

Abline doesn't work in R

It may happen that you are plotting a linear regression line with abline command in R and that it didn't appear on the graph.
Most probable explanation (as it was for me) is that you have to inverse x and y in abline.

> plot(merge, col="blue", cex=1.5, xlab="X axis title", ylab="Y axis title", main="Main title of the graph")

> abline(lm(merge[,1]~merge[,2]), col=14, lwd=2)

Didn't work but this worked:

> plot(merge, col="blue", cex=1.5, xlab="X axis title", ylab="Y axis title", main="Main title of the graph")

> abline(lm(merge[,2]~merge[,1]), col=14, lwd=2)




No comments:

Post a Comment