add x=y line to scatterplot

CadisEtRama picture CadisEtRama · Dec 6, 2013 · Viewed 44.7k times · Source

I am using the scatterplot function from the car package to generate a scatterplot. I want to be able to generate a reference line in the plot that should be x=y. I tried using abline and it does add a line but it is not the x=y line. Can someone help?

My code is as follows:

scatterplot(phenos$P1~pheno$P0, data=pheno,spread=FALSE,ylab="6 month timepoint", xlab="Baseline Timepoint", jitter=list(x=1, y=1))
abline(0,1)

Thanks.

Answer

Alemnew Sheferaw Asrese picture Alemnew Sheferaw Asrese · Mar 28, 2017

You can achieve your goal by the same function abline. Use the function abline(a=0, b=1) where a and b are the intercept and slop of the line respectively. This draws you a straight line of the form Y = a + b*x.

Hope this helps.