[R] lattice chart: different definitions for series

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Nov 7 21:23:32 CET 2005


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