[R] levelplot in lattice

deepayan.sarkar at gmail.com deepayan.sarkar at gmail.com
Thu Jun 28 05:00:04 CEST 2007


On 6/27/07, adschai at optonline.net <adschai at optonline.net> wrote:
> Sorry. My email editor from my ISP always screws up the text after sending
> out. Below is my response to you (in plain text).
>
> Thank you Deepayan. Let's do the following exercise to reproduce the problem
> I'm facing. In the following code, I tried to have plot.rw1 and plot.rw2
> shows in two separate rows on my plot windows. However, after the call to
> the 2nd levelplot, plot of plot.rw2 replace my first plot and the result
> shows only 1 row on my windows. Any lights on this would be really
> appreciated. Thank you
>
> x <- seq(0.1,1,0.1);
> y <- seq(0.1,1,0.1);
> dat <- rnorm(4*length(x)*length(y));
>
> Pa.dat <- expand.grid(x,y);
> Pa.dat$z <- dat[1:100];
> Pa.dat$cond <- "Pa";
>
> plot.rw1 <- Pa.dat;
>
> Pb.dat <- expand.grid(x,y);
> Pb.dat$z <- dat[101:200];
> Pb.dat$cond <- "Pb";
>
> plot.rw1 <- rbind(plot.rw1, Pb.dat);
> names(plot.rw1) <- c("x","y","z","cond");
>
> Days1.dat <- expand.grid(x,y);
> Days1.dat$z <- dat[201:300];
> Days1.dat$cond <- "Day Work";
>
> plot.rw2 <- Days1.dat;
>
> Days2.dat <- expand.grid(x,y);
> Days2.dat$z <- dat[301:400];
> Days2.dat$cond <- "Day Rest";
>
> plot.rw2 <- rbind(plot.rw2, Days2.dat);
> names(plot.rw2) <- c("x","y","z","cond");
>
> windows();
> par(mfrow=c(2,1));
> levelplot(z ~ x*y|cond, plot.rw1);
> levelplot(z ~ x*y|cond, plot.rw2);


## option 1:

levelplot(z ~ x * y | cond,
          make.groups(plot.rw1, plot.rw2))

## equivalent in this case

levelplot(z ~ x * y | cond,
          rbind(plot.rw1, plot.rw2))

## option 2 (not exactly the same)

print(levelplot(z ~ x*y|cond, plot.rw1),
      split = c(1, 2, 1, 2))
print(levelplot(z ~ x*y|cond, plot.rw2),
      split = c(1, 1, 1, 2),
      newpage = FALSE)

-Deepayan



More information about the R-help mailing list