[R] plot() and lines() multivariate problem

Fred Jean frederic.jean at univ-brest.fr
Fri Jan 10 17:45:03 CET 2003

Dear list

I'm trying to solve the following problem since 2 days with no success. 
Could someone help a newbie, please ?

I have a  dependant variable which is diameter of shell, and two factors
which are level on the beach (3 levels 'B', 'E' and 'H') and a hydrodynamics
indice (3 levels 1, 2 and 3)

To study diameter variations according to these factors, I may use something
like :
> mod <- lm(diameter  ~ level * hydro)

When I want to look at the graphical results of such a model on a 
scatterplot, I use

> plot(diameter ~ as.integer(hydro), col = as.integer(level))

and to draw the model lines :

> lines(as.integer(hydro)[lev=='B'], predict(mod)[lev=='B'], col = 1)
> lines(as.integer(hydro)[lev=='E'], predict(mod)[lev=='E'], col = 1)
> lines(as.integer(hydro)[lev=='H'], predict(mod)[lev=='H'], col = 1)

But sometimes, the lines are not drawn in the order of the levels of hydro but
as a *zigzag* and lines() commands seem to draw lines going from level 1
to level 3 and then back to level 2 of the x axis (hydro)

I hope this description is comprehensible. Could someone explain me how to
avoid this ?

Many thanks for giving me some of your time.

C'est curieux chez les marins, ce besoin de faire des phrases (M.A.)
Univ. Bretagne Occidentale - Inst. Univ. Européen de la Mer
Place Nicolas Copernic F-29280 PLOUZANE
Pho:+33 (0)2 98 49 86 38 // Fax:+33 (0)2 98 49 86 45

More information about the R-help mailing list