Monday, 15 July 2013

plot - how to define graphical bounds of abline linear regression in R -



plot - how to define graphical bounds of abline linear regression in R -

i trying truncate ends of abline, linear regression of data.

fit1=lm(logy~logx) > fit1 call: lm(formula = logy ~ logx) coefficients: (intercept) logx -5.339 -2.115

where logx log10(x[1:365] transformed. logy follows same code. when plot abline(fit1,col="red"), line wanted, line extends past bounds have set [1:365]. have tried par=xpd , doesn't cut down line limits want. i've played around segments() no avail. maybe line() argument?

edit here new solution:

#the next vectors x , y store our info want plot x<-(1:10) y<-(10:1) plot(x,y,type="l",log="xy") #we want linear regression on our log10 transformed info , add together line plot logy=log10(y[3:8]) logx=log10(x[3:8]) fit1=lm(logy~logx) #finally, want regression line seem applies on range 3 8 clip(3,8,8,3) abline(fit1,col="red")

what yields plot line (now, not) extends past 3 8 on our x-axis. want regression line display x=3 x=8, next same slope.

you can clip drawing area. can not utilize info illustration not reproducible, here illustration:

> plot(1,1,type='n',xlim=c(0,400), ylim=c(0,10)) > clip(1,365,0,10) > abline(h=5,col='red')

results in line bounded within box of coordinates x0=1,x1=365,y0=0,y1=10:

r plot linear-regression

No comments:

Post a Comment