[R] plot() and lines() multivariate problem
ligges at statistik.uni-dortmund.de
Fri Jan 10 18:26:02 CET 2003
Fred Jean wrote:
> 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)
All data must be sorted according to the hydro variable.
> I hope this description is comprehensible. Could someone explain me how to
> avoid this ?
> Many thanks for giving me some of your time.
You are looking for interaction.plot(), I think, see ?interaction.plot
More information about the R-help