[R] Plotting 1 covariate, 3 factors

Paul Chatfield p.s.chatfield at rdg.ac.uk
Wed Oct 7 18:00:48 CEST 2009


I'm interested in plotting a y with an x factor as the combination of 2
factors and colour with respect to a third, which the code below does with
interaction.plot().  However, this is because I redefine the x to be 1
factor.  Is there a way of getting it to plot without redefining it, and
ideally to not join up the lines BETWEEN levels a and b, but just join those
between after and before for one level of f3.  I figure this could be done
by manually drawing over blank lines using ?lines but am not sure what the
coordinates would be and figured there is probably an easier way where
someone has dealt with this before.  Any thoughts greatly appreciated,

Paul

#####

y<-rnorm(36)
f1<-rep(c("after","before"), 18)
f2<-rep(1:3,12)
f3<-rep(1:2, each=18)

## Define new factor to be f1 and f3 for x axis - clumsy code, but gets its
done;

ff<-numeric(length(y))
for (i in 1:length(y))
{if (f1[i]=="a" & f3[i]==1) ff[i]<-"1, a"
else if(f1[i]=="a" & f3[i]==2) ff[i]<-"2, a"
else if(f1[i]=="b" & f3[i]==1) ff[i]<-"1, b"
else ff[i]<-"2, b"}

## Plot of interest;

interaction.plot(ff,f2,y)
-- 
View this message in context: http://www.nabble.com/Plotting-1-covariate%2C-3-factors-tp25789442p25789442.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list