[R] color under lm line

Dieter Menne dieter.menne at menne-biomed.de
Tue Mar 15 14:21:35 CET 2011


Marlin Keith Cox wrote:
> 
> Thank you, but I need only the area under the llm colored.  What if there
> were two lm lines? 
> 
For the well-behaved case  you could find the range to be colored with

range = which(diff(resid(llm)>0)!=0)

Dieter

x=seq(0,5,len=100)
y=-(x-5)^2
llm<-lm(y~x)
range = which(diff(resid(llm)>0)!=0)
co <- coef(llm)
bord <- pmin(y, co[1] + co[2] * x)
plot(x,y)
r1 = range[1]
r2 = range[2]
polygon(c(x[r1],x[r1],x[r2],x[r2]),
        c(min(y),y[r1],y[r2],min(y)),
        col = 'red')
abline(co)



--
View this message in context: http://r.789695.n4.nabble.com/color-under-lm-line-tp3355317p3356538.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list