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

From: Dieter Menne <>
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


to find what is possible.


# ---------------------------------------------------
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){
    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(

      left.padding = -1

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


View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
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 Please read the posting guide before posting to the list.

list of date sections of archive