[R] plotting multivariate data and lm()

Fred Jean frederic.jean at univ-brest.fr
Wed Jan 8 17:17:06 CET 2003


Dear list,

I have a problem with plotting multivariate data and models. 
I suppose the answer is obvious for experienced users but I didn't find it
looking in usual documentation or in the mail archive...

Let's say I use a dataset like :

a <- sort(round(rnorm(90),3))
niv <- factor(c(rep('B',30), rep('E', 30), rep('H',30)),labels=c('B','E','H'))
cl3 <- factor(rep(sequence(1:3),15))
mat <- cbind(a,niv,cl3)

let's say I want a model like :
mod <- lm(a~niv*cl3)        #silly, just for example

I want to obtain a scatterplot of 'a' vs. 'cl3', taking into account the 
value of 'niv' so I use :
plot(a~as.integer(cl3), col=as.integer(niv))

NB : I don't use lm(a~cl3) because the output is a boxplot in this case.

Is there a simple way to obtain the 3 regression lines for the 3 levels 
of 'niv' on this scatterplot ?

I tried a solution using lines() or abline() and expressions with
mod$coefficients[n], but it becomes very complicated as the number
of levels and interactions increase.

Maybe my plotting method is totally wrong ?

Many thanks for taking time for a newbie.


-- 
C'est curieux chez les marins, ce besoin de faire des phrases (M.A.)
----------------------------------------------------
Fred JEAN - UMR CNRS 6539 / LEMAR
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