I made up some data since you didn't send your example.

tmp <- data.frame(x=rep(1:10, 3),
                  y=rnorm(30),
                  Fam=rep(c("a","b","c"), each=10),
                  Spacing=rep(c("A","B"), each=5, times=3))

xyplot(y ~ x | Fam, groups=Spacing, data=tmp, layout=c(3,1), auto.key=TRUE)


Please send your sample data in dump format, for example,
 dump("tmp", "")

Pick up the results of that statement and put that in the email.
Then we can pick up the email and drop it into R and reproduce exactly what
you are using.  Like this

> dump("tmp", "")
tmp <-
structure(list(x = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L), y = c(-0.0345071002647472, -0.610639808963399,
-0.948653110651411, -0.92008674650768, -0.985533084792987,
0.555592739326888,
-0.196867265537583, 1.08431153910752, -1.09082920912172, 0.480868223859436,
-0.778093952257941, -1.55719016273097, -0.141816251366503,
-0.663457658736608,
0.881314461950796, -0.343766582202738, -1.34605330134113,
0.312527972650107,
-1.53177710459328, 0.676386152716744, 0.670427578188405, 0.259979521481335,
0.0426301121833324, 1.18197979394659, -1.45595482489071,
-0.185395542472854,
-1.06421668318033, -1.54156980611217, -0.0793192509632766, 0.161617397470246
), Fam = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L), .Label = c("a", "b", "c"), class = "factor"),
    Spacing = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
    2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
    1L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor")),
.Names = c("x",
"y", "Fam", "Spacing"), row.names = c(NA, -30L), class = "data.frame")
>



On Wed, Oct 31, 2012 at 7:09 PM, yzh lin <yzhlinscau@gmail.com> wrote:

> Hi everybody,
>
> I recently used xyplot, but I found that for control flow can't work in the
> xyplot. The program code and some of my data file are shown as follow.
> Would someone please tell me where my code is wrong and how can make the
> code right?
>
> Thanks.
>
> Best regards
> Yuanzhen Lin
>
>
> Code:
>
> library("lattice")
>
> plot.data$Fam<-as.numeric(plot.data$Fam)
>
> #### xyplot can work if one by one in  Fam ####
>     plot3.data<-subset(plot.data,Fam==1)
>     heading=paste("Fam_",1)
>     xyplot(rank ~ ca, data=plot3.data, groups=Spacing,
> type="o",main=heading)
>
>
> ###### the following code for control flow doesn't work ####
> for (i in 1:3){
>     plot3.data<-subset(plot.data,Fam==i)
>     heading=paste("Fam_",i)
>     xyplot(rank ~ ca, data=plot3.data, groups=Spacing,
> type="o",main=heading)
> }
>
> ############ data format ######
> data format of plot.data shows as folow:
>  Fam Fam2 Spacing ca rank  1 Fam_70001 S2 1 14  1 Fam_70001 S2 2 46  1
> Fam_70001 S2 3 49  1 Fam_70001 S2 4 47  1 Fam_70001 S2 5 54  1 Fam_70001 S3
> 1 18  1 Fam_70001 S3 2 38  1 Fam_70001 S3 3 34  1 Fam_70001 S3 4 27  1
> Fam_70001 S3 5 29  2 Fam_70002 S2 1 8  2 Fam_70002 S2 2 12  2 Fam_70002 S2
> 3
> 25  2 Fam_70002 S2 4 8  2 Fam_70002 S2 5 13  2 Fam_70002 S3 1 26  2
> Fam_70002 S3 2 22  2 Fam_70002 S3 3 19  2 Fam_70002 S3 4 14  2 Fam_70002 S3
> 5 7
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]


