[R] Plotting 1 covariate, 3 factors

Paul Chatfield p.s.chatfield at rdg.ac.uk
Thu Oct 8 10:57:59 CEST 2009


Cheers guys that's helpful.  Doug, you're right, my code for ff should have
been

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

As I have factors with only 2,2 and 3 levels respectively, your approach
suits the problem perfectly.  Just to round this off, trying to reorient it
back to having the y on axis 2 seems to mean the line now does "dot-to-dot"
instead of fitting the average.  Am I being dim in missing a key option in
my statement below which would correct this as your code did, Doug, when
oriented the other way, or does it require some kind of panel statement?

dotplot(y~f2|f1, groups=f3, layout=c(2,1), strip=T, type=c("a","p"), pch=19)

Thanks

Paul


Douglas Bates-2 wrote:
> 
> I'm not sure if this is exactly what you are looking for but I would
> generally create an interaction plot using the lattice 'dotplot' with
> type = c("p","a") so I get both the original data and the lines
> joining the averages for the different factor levels.  I also prefer
> the horizontal orientation to the vertical orientation.  Combining all
> these variations produces something like
> 
> dotplot(f2 ~ y | f1, groups = f3, aspect = 0.2, layout = c(1,2), type
> = c("p","a"), pch = 21, strip = FALSE, strip.left = TRUE, auto.key =
> list(columns = 2, lines = TRUE))
> 
-- 
View this message in context: http://www.nabble.com/Plotting-1-covariate%2C-3-factors-tp25789442p25800572.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list