[R] Odp: Regression line w/ residuals - tuning the plot

Petr PIKAL petr.pikal at precheza.cz
Wed Sep 30 11:54:49 CEST 2009


Hi

As you did not provide any piece of code I done some myself

 x<-1:20
 y<-5*x+3+rnorm(20)
 plot(x,y)
 fit<-lm(y~x)
 par(mfrow=c(2,1))
 plot(x,y)
 abline(fit)
 plot(x, resid(fit))

I do not see any problem with this. If you want to set up margins use

par(mar=....)

par(mar=c(0,4,4,1))
plot(x,y, axes=F)
axis(2)
box()
abline(fit)
par(mar=c(5,4,0,1))
plot(x, resid(fit))

Regards
Petr

r-help-bounces at r-project.org napsal dne 28.09.2009 17:19:27:

> Hello everybody,
> 
> I am sure this is a beginners' problem which is being asked
> recurrently every few months, but nevertheless I wasn't able to find
> the answer searching through the r-help list.
> 
> So here is my problem: I would like to plot a set of points (y vs. x),
> a (linear) regression line through them, and on the second graph
> underneath the first one I would want to plot residuals vs. x. I came
> up with two solutions, unfortunately neither of them is fully
> satisfactory.
> 
> First I tried with what I later learned is called traditional graphics
> (file norris.R). Here, the white space margins around the plots are
> too wide, meaning that the data in the plot are crammed. Probably I
> would be quite happy if I could somehow define a rectangular plotting
> area with its height being ~150% of its width, but I cannot prevent R
> from offering me a square plotting area.
> 
> Next I tried a lattice package (file norris.lattice.R). Here, the
> margins are smaller, but the lower plot does not fit exactly under the
> upper one (the x-axes should match).
> 
> Most likely I am not using the correct terminology (if I would have
> known it, I could have looked in the help pages myself, thank you :),
> but I hope that the attached files make more sense of what I am trying
> to do.
> 
> Thanks in advance.
> 
> All the best,
> Primoz
> 
> -- 
> Primož Peterlin,   Inštitut za biofiziko, Med. fakulteta, Univerza v 
Ljubljani
> Lipičeva 2, SI-1000 Ljubljana, Slovenija. primoz.peterlin at mf.uni-lj.si
> Tel +386-1-5437612, fax +386-1-4315127,  
http://biofiz.mf.uni-lj.si/~peterlin/
> F8021D69 OpenPGP fingerprint: CB 6F F1 EE D9 67 E0 2F  0B 59 AF 0D 79 56 
19 0F
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list