A few problems ... This statement doesn't make sense. seq(-0.08, -0.02, len = -0.02) Perhaps you meant seq(-0.08, -0.02, by = 0.02)
The xlim= and ylim= are arguments to higher level plot functions, like plot(), and won't work for functions lines() or abline(). Are you trying to limit the range of the predicted line on the graph? If so, perhaps the following simple example will help. # randomly generate some fake data CWSI <- rnorm(20, sd=0.1) NWI <- rnorm(20, sd=0.1) # linear regression reg1 <- lm(CWSI~NWI) # show predicted line for small segment newNWI <- seq(-0.08, -0.02, by = 0.02) plot(NWI, CWSI) lines(newNWI, predict(reg1, list(NWI = newNWI))) Jean On Mon, Oct 28, 2013 at 10:30 AM, Ahmed Attia <ahmedati...@gmail.com> wrote: > Hi > > I have a question about drawing a linear line in x, y plot. I usually > use the following code, but for this time the x values are to small > (-0.08 to -0.02) > > I wrote the following code, but r does not draw the line. However, it > does not give an error when it takes the code. > > > reg1<- lm(CWSI~NWI, data=Ahmed) > > NWI <- seq(-0.08, -0.02, len = -0.02) > lines(NWI, predict(reg1, list(NWI = > NWI)),xlim=c(-0.08,-0.02),ylim=c(0,1),pch=1,col=1,lwd=2, lty=1) > > When I wrote the following code > > abline(reg1,pch=2,col=2,lwd=2, lty=2,xlim=c(-0.06,-0.02),ylim=c(0.3,0.8)) > > the line shows up, but I can not control the xlim or ylim. It bascally > goes across the figure > > I appreciate your help > -- > Ahmed M. Attia > > > Research Assistant > Dept. Of Soil&Crop Sciences > Texas A&M University > ahmed.at...@ag.tamu.edu > Cell phone: 001-979-248-5215 > > ______________________________________________ > 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]] ______________________________________________ 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.