[R] Layout within levelplot from the lattice package
Dieter Menne
dieter.menne at menne-biomed.de
Wed Apr 6 15:39:46 CEST 2011
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.
More information about the R-help
mailing list