[R] Plotting 1 covariate, 3 factors

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Oct 8 11:13:10 CEST 2009


On Thu, Oct 8, 2009 at 1:57 AM, Paul Chatfield <p.s.chatfield at rdg.ac.uk> wrote:
>
> 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)

All you probably need is to make f2 a factor (e.g., y ~ factor(f2) |
f1). Otherwise dotplot() doesn't know which one to treat as
categorical.

-Deepayan




More information about the R-help mailing list