[R] how can xyplot word when with for control flow

Rolf Turner rolf.turner at xtra.co.nz
Thu Nov 1 01:20:06 CET 2012


See FAQ 7.22.

     cheers,

         Rolf Turner

On 01/11/12 12:09, yzh lin 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




More information about the R-help mailing list