Re: [R] Layout within levelplot from the lattice package

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Wed, 06 Apr 2011 06:39:46 -0700 (PDT)

Ian Renner wrote:
>
> Hi,
>
> I'm a novice with levelplot and need some assistance! Basically, I want a
> window
> which contains 6 levelplots of equal size presented in 3 columns and 2
> rows.
> ...
> Is there any way to concatenate levelplots from a factor vertically as
> opposed
> to horizontally?
>
>

Thank for providing a self-contained example. Remembering my early struggles with lattice, you must have needed some hours to get this working! Your last question is easy to answer: use a slightly different version of split (see below). To keep the code more transparent, separating plot generation from display, I prefer the following scheme:

p = xyplot(...)
print(p, split....)

Normally one would try to use one data frame and panels for your type of plot, but as I see this cannot be done here because you want different color regions which is not vectorized. So doing it in three runs seems to be fine, if Deepayan has no other solution.
To get the plots closer together you must find the correct par.settings. This is one of the tricky parts in lattice, but try

str(trellis.par.get())

to find what is possible.

Dieter

# ---------------------------------------------------
library(lattice)
start = expand.grid(1:10,1:14)
start2 = rbind(start,start,start,start,start,start) z = rnorm(840)
factor.1 = c(rep("A", 280), rep("B", 280), rep("C", 280))
factor.2 = c(rep("1", 140), rep("2", 140), rep("1", 140), rep("2", 140),
rep("1", 140), rep("2", 140))

data = data.frame(start2, z, factor.1, factor.2)

   names(data)[1:2] = c("x", "y")

data.A = data[data$factor.1 == "A",]
data.B = data[data$factor.1 == "B",]
data.C = data[data$factor.1 == "C",]

## End of data generation

doLevels = function(data, col.regions){
  levelplot(z~x*y|factor.2,data,
    col.regions=col.regions,asp="iso",xlab = "",     ylab = "", colorkey = list(space="bottom"),     scales=list(y=list(draw=F),x=list(draw=F)),     par.settings=list(layout.widths=list(

      right.padding=-1,
      left.padding = -1
      ))

    )
}
p1 = doLevels(data.A,heat.colors)
p2 = doLevels(data.B,topo.colors)
p3 = doLevels(data.C,terrain.colors)

print(p1,split=c(1,1,3,1),more=TRUE)

print(p2,split=c(2,1,3,1),more=TRUE)
print(p3,split=c(3,1,3,1))
--
View this message in context: http://r.789695.n4.nabble.com/Layout-within-levelplot-from-the-lattice-package-tp3430421p3430812.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 06 Apr 2011 - 13:46:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Apr 2011 - 15:40:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive