[R] lattice chart: different definitions for series

ManuelPerera-Chang@fmc-ag.com ManuelPerera-Chang at fmc-ag.com
Tue Nov 8 12:12:11 CET 2005





Dear Deepayan,

Thank you very much for the example.

Now I am missing the grids inside my graph. As shown in my sample code
yesterday, before I had them defined in the

panel=function(x,y,...){panel.grid(h=-1,v=-1,col="grey",lty=2,cex=0.1)}

and they were properly drawn, but you did not use this approach in your
example, and my guesses this morning to place them together with your code
failed.

Sorry for my newbee question ..

My best regards,

Manuel

PS.: As for my "experiments", I was trying to use the document "Panel
Function for Display Marked by groups", that you wrote. In this document I
cannot see that e.g. all the arguments for panel.superpose.2 are optionals,
as in your example below.

Further in this documentation you explained:

"panel.groups - the panel function to be used for each group of points.
Defaults to panel.xyplot (behavior in S) "

and then ..

"type -  usually a character vector specifying what should be drawn for
each group, passed on to the panel.groups function, which must know what to
do with it. By default this is panel.xyplot ..."

consecuently I was trying to use "type" as an argument to panel.groups, but
without success.




                                                                                                                                       
                      Deepayan Sarkar                                                                                                  
                      <deepayan.sarkar@        To:       ManuelPerera-Chang at fmc-ag.com                                                 
                      gmail.com>               cc:       r-help at stat.math.ethz.ch                                                      
                                               Subject:  Re: lattice chart: different definitions for series                           
                      07.11.2005 21:23                                                                                                 
                                                                                                                                       
                                                                                                                                       




On 11/7/05, ManuelPerera-Chang at fmc-ag.com <ManuelPerera-Chang at fmc-ag.com>
wrote:
>
>
>
>
> Hi enthusiasts,
>
> Trying to create a single chart in  lattice with different plotting
> definitions for the different series (two series should be drawn with
lines
> and the other without them)
>
> I am using a dataset, which includes a grouping variable e.g. clinic with
> three levels, the variable "year" and a continous variable: "mct".
>
> In the graph the variable "year" is in the x axis, with "mct" represented
> in the y axis.
>
> The diagram should include two line diagrams(representing two of the
> groups) , with the third group represented only with symbols(no lines).
>
> Until now I was using white lines to eliminate the lines drawn in the
third
> group, but this solution is not optimal, as the grids are sometimes not
> visible
>
> sp<-list(superpose.symbol=list(pch=c(1,2,1),col=c("blue","red","green")),
>        superpose.line=list(col=c("blue","red","white"),lty=c(1,2,)))
>
> ... and then including
>
> print(xyplot(mct~trend.data$year,groups=clinic,
>   scales=list(x=list(at=c(15:pno),labels=per.labels)),
>   main=main.title,
>   sub=sub.title,
>   xlab=x.label,
>   ylab=y.label,
>   xlim=c(pno-12,pno+1),
>   panel=function(x,y,...){panel.grid(h=-1,v=-1,col="grey",lty=2,cex=0.1);
>                   panel.superpose(x,y,type="l",lwd=1.8,...);
>                   panel.superpose(x,y,type="p",cex=1.8,...))},
>   key=sk,
>   par.settings=sp));
>
> ... was also experimenting, and searching a lot in the WWW for
>
> panel.superpose.2 and type=c("b","b","p"), but without success.

I don't know what experiments you did, but the following seems to work
fine for me:

library(lattice)

mydf <-
    data.frame(year = rep(1991:2000, 3),
               mct =
               rnorm(30,
                     mean = rep(1:3, each = 10),
                     sd = 0.5),
               clinic = gl(3, 10))

xyplot(mct ~ year, mydf, groups = clinic,
       panel = panel.superpose.2,
       type = c("b", "b", "p"))

-Deepayan




More information about the R-help mailing list