# [R] xyplot : superimposed 2 groups in different panels

Peter Ehlers ehlers at ucalgary.ca
Tue Nov 30 17:05:39 CET 2010

```On 2010-11-30 06:50, PtitBleu wrote:
>
> Hello,
>
> I would like to plot the following xyplot : for each date of fff (1 date per
> panel), bbb=f(aaa) for the two groups (ddd=1 and ddd=2) superimposed.
>
> I can do it by group (see below) but not together.
> I looked at http://lmdvr.r-forge.r-project.org/figures/figures.html but I
> haven't found what I was looking for (to be honest, I haven't understood all
> the examples).
>
> Any help will be welcome.
> Ptit Bleu.
>
>
> # aaa : x-axis
> # bbb : y-axis
> # ddd : group 1 or group 2
> # fff : 2 different dates
>
> aaa<-rep(seq(1:100),2)
> bbb<-aaa*aaa*c(rep(1,50),rep(0.5,50))
> ddd<-c(rep(1,50),rep(2,50))
> fff<-rep(c(rep("2010-11-01",25),rep("2010-11-10",25)),2)
>
> library(lattice)
> # bbb as a function of aaa by date for the first group (ddd=1)
> x11()
> xyplot(bbb[ddd==1] ~ aaa[ddd==1] | fff[ddd==1], col="red", main="1")
> # bbb as a function of aaa by date for the second group (ddd=2)
> x11()
> xyplot(bbb[ddd==2] ~ aaa[ddd==2] | fff[ddd==2], col="blue", main="2")
>
> # bbb as a function of aaa by date for ddd=1 AND bbb as a function of aaa by
> date for ddd=2 in the same panels
> ???
>
I *think* that you want

xyplot(bbb ~ aaa | fff, groups = ddd, col = c("red", "blue"))

but maybe this

xyplot(bbb ~ aaa | ddd * fff)

Peter Ehlers

```