Hi, I would like to add a color under a lm line and not the plotted line. Is this possible? In the example, I do not want the area under the curve red, but rather under the llm line. x=seq(0,5,len=100) y=-(x-5)^2 llm<-lm(y~x) plot(x,y) polygon(c(x,x[length(x)]), c(y, y[1]), col='red') abline(llm) keith -- M. Keith Cox, Ph.D. Alaska NOAA Fisheries, National Marine Fisheries Service Auke Bay Laboratories 17109 Pt. Lena Loop Rd. Juneau, AK 99801 Keith.Cox@noaa.gov marlinkcox@gmail.com U.S. (907) 789-6603 [[alternative HTML version deleted]]
Hi: Try this: co <- coef(llm) bord <- pmin(y, co[1] + co[2] * x) plot(x,y) polygon(c(x, x[length(x)]), c(bord, bord[1]), col = 'red') abline(co) HTH, Dennis On Mon, Mar 14, 2011 at 4:02 PM, Marlin Keith Cox <marlinkcox@gmail.com>wrote:> Hi, > I would like to add a color under a lm line and not the plotted line. Is > this possible? In the example, I do not want the area under the curve red, > but rather under the llm line. > > x=seq(0,5,len=100) > y=-(x-5)^2 > llm<-lm(y~x) > plot(x,y) > polygon(c(x,x[length(x)]), c(y, y[1]), col='red') > abline(llm) > keith > > -- > M. Keith Cox, Ph.D. > Alaska NOAA Fisheries, National Marine Fisheries Service > Auke Bay Laboratories > 17109 Pt. Lena Loop Rd. > Juneau, AK 99801 > Keith.Cox@noaa.gov > marlinkcox@gmail.com > U.S. (907) 789-6603 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hi Keith, how about this: fit<-function(x,coefs) x*coefs[2]+coefs[1] plot(1:10,1:10,type="n") x<-par("usr")[1:2] cf1<-c(a=3,b=.5) #eg coefs from a lm-object cf2<-c(a=1,b=.9) #another line, coloring only intersection polygon(c(x,rev(x)),c(fit(x,cf1),fit(rev(x),cf2)),col="red") setting one of the coef vectors to c(0,0) colors the area under the other line. hth. Am 15.03.2011 00:02, schrieb Marlin Keith Cox:> Hi, > I would like to add a color under a lm line and not the plotted line. Is > this possible? In the example, I do not want the area under the curve red, > but rather under the llm line. > > x=seq(0,5,len=100) > y=-(x-5)^2 > llm<-lm(y~x) > plot(x,y) > polygon(c(x,x[length(x)]), c(y, y[1]), col='red') > abline(llm) > keith >-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790