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

Primoz PETERLIN primozz.peterlin at gmail.com
Mon Sep 28 17:19:27 CEST 2009


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


More information about the R-help mailing list