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. I've tried to approach it two ways. The first way leads to this question: Is there any way to concatenate levelplots from a factor vertically as opposed to horizontally? I'd like to pair the levelplots by factor.2 on top of each other with the colorkey at thebottom, resulting in 3 columns of paired levelplots. I can only get 3 rows of paired levelplots. Here is some mock code to illustrate the point: 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",] print(levelplot(z~x*y|factor.2,data.A,col.regions=heat.colors,asp="iso",xlab = "", ylab = "", colorkey = list(space="bottom"), scales=list(y=list(draw=F),x=list(draw=F))),split=c(1,1,1,3)) print(levelplot(z~x*y|factor.2,data.B,col.regions=topo.colors,asp="iso",xlab = "", ylab = "", colorkey = list(space="bottom"), scales=list(y=list(draw=F),x=list(draw=F))),split=c(1,2,1,3),newpage=FALSE) print(levelplot(z~x*y|factor.2,data.C,col.regions=terrain.colors,asp="iso",xlab = "", ylab = "", colorkey = list(space="bottom"), scales=list(y=list(draw=F),x=list(draw=F))),split=c(1,3,1,3),newpage=FALSE) My other approach has been to plot the 6 levelplots individually so that I can control the placement. However, I'd like to have the paired levelplots touch as they do in my first approach, and I'd like them to be the same size, despite having the colorkey only below one of the plots. Also, I'd like to put more space between the plot and the colorkey. Is there a way to manual control the size of the individual plot windows? Here is some additional code to illustrate this point: data.A1 = data.A[data.A$factor.2 == "1",] data.A2 = data.A[data.A$factor.2 == "2",] data.B1 = data.B[data.B$factor.2 == "1",] data.B2 = data.B[data.B$factor.2 == "2",] data.C1 = data.C[data.C$factor.2 == "1",] data.C2 = data.C[data.C$factor.2 == "2",] print(levelplot(z~x*y,data=data.A1,col.regions=heat.colors,asp="iso",xlab = "", ylab = "",main="Method A",scales=list(y=list(draw=F),x=list(draw=F)),colorkey=FALSE),split=c(1,1,3,2)) print(levelplot(z~x*y,data=data.A2,col.regions=heat.colors,asp="iso",xlab = "", ylab = "", scales=list(y=list(draw=F),x=list(draw=F)),colorkey=list(space="bottom")),split=c(1,2,3,2),newpage=FALSE) print(levelplot(z~x*y,data=data.B1,col.regions=topo.colors,asp="iso",xlab = "", ylab = "", main="Method B",scales=list(y=list(draw=F),x=list(draw=F)),colorkey=FALSE),split=c(2,1,3,2),newpage=FALSE) print(levelplot(z~x*y,data=data.B2,col.regions=topo.colors,asp="iso",xlab = "", ylab = "", scales=list(y=list(draw=F),x=list(draw=F)),colorkey=list(space="bottom")),split=c(2,2,3,2),newpage=FALSE) print(levelplot(z~x*y,data=data.C1,col.regions=terrain.colors,asp="iso",xlab = "", ylab = "", main="Method C",scales=list(y=list(draw=F),x=list(draw=F)),colorkey=FALSE),split=c(3,1,3,2),newpage=FALSE) print(levelplot(z~x*y,data=data.C2,col.regions=terrain.colors,asp="iso",xlab = "", ylab = "", scales=list(y=list(draw=F),x=list(draw=F)),colorkey=list(space="bottom")),split=c(3,2,3,2),newpage=FALSE) Any help would be greatly appreciated! Ian [[alternative HTML version deleted]]
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.
Hi Dieter, Thank you for that! Your post helped me on my way by introducing me to the padding settings within lattice, and I'm nearly there now. My new problem related to this graph is that I would like to add a polygon to one of the panels, but it seems that my code also adds the polygon to the paired panel. Is there a way to condition it so that it only appears on the top panel in column 3? Here is my updated code: 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",] plot.A = levelplot(z~x*y|1*factor.2,data.A,col.regions=heat.colors, strip = FALSE, asp="iso",xlab = "", ylab = "", colorkey = list(space="bottom"), scales=list(y=list(draw=F),x=list(draw=F))) plot.B = levelplot(z~x*y|1*factor.2,data.B,col.regions=topo.colors, strip = FALSE, asp="iso",xlab = "", ylab = "", colorkey = list(space="bottom"), scales=list(y=list(draw=F),x=list(draw=F))) plot.C = levelplot(z~x*y|1*factor.2,data.C,col.regions=terrain.colors, strip = FALSE, asp="iso",xlab = "", ylab = "", colorkey = list(space="bottom"), scales=list(y=list(draw=F),x=list(draw=F)), panel = function(x, y, subscripts, ...) { panel.levelplot(x, y, subscripts, ...) panel.polygon(c(2, 5, 5, 2), c(3, 3, 8, 8), col="blue") } ) print(plot.A, split=c(1,1,3,1)) print(plot.B, split=c(2,1,3,1), newpage = FALSE) print(plot.C, split=c(3,1,3,1), newpage = FALSE) Thanks again for your help! [[alternative HTML version deleted]]