[R] equation on graph

Agus Susanto gusanto at gmail.com
Mon Apr 27 17:33:54 CEST 2009


Dear all,
I want to write regression equation on R graph by taking the actual
values of the regression coefficients. I have problem when writing X^2
(printed as X superscripts 2). I know there's a function "expression"
but still no luck to use it in this case. 

Below is the R code as an example:
plot(x,y,col=2)
reg.quad<-lm(y~x+I(x^2))
quad.fit<-coef(reg.quad)[1]+coef(reg.quad)[2]*x+coef(reg.quad)[3]*x^2
lines(x,quad.fit,lty=1)
text(4,1,paste("y=",round(coef(reg.quad)[1],4),round(coef(reg.quad)[2],4),"X",round(coef(reg.quad)[3],4),"X^2"),col=4)

Thanks in advance.




More information about the R-help mailing list