I want to create a simple plot containing three levelplots with one colorbar. I used the "Three levelplots" code below, but the third levelplot is drawn smaller than the first two. However, if I try the "Two levelplots" code below it works well. Can anybody tell me how could I draw three levelplots (of the same size) with one colorbar. Thanks in advance, Joaquin ### Three levelplots ### frame <- matrix(rnorm(16*48), nrow=16) p <-levelplot(frame, colorkey=FALSE) print(p, position=c(0,0,1/3,1), more=TRUE) p <-levelplot(frame, colorkey=FALSE) print(p, position=c(1/3,0,2/3,1), more=TRUE) p <-levelplot(frame, colorkey=TRUE) print(p, position=c(2/3,0,3/3,1), more=FALSE) ### Two levelplots ### frame <- matrix(rnorm(16*48), nrow=16) p <-levelplot(frame, colorkey=FALSE) plot(p, position=c(0,0,1/2,1), more=TRUE) p <-levelplot(frame, colorkey=TRUE) plot(p, position=c(1/2,0,1,1), more=FALSE) -- Joaquin Rapela PhD Student, Electrical Engineering University of Southern California 3641 Watt Way, Los Angeles, CA 90089-2520 tel/fax: (213) 821-2070 http://www-scf.usc.edu/~rapela ---------------------------------- Player King: And hitherto doth love on fortune tend: For who not needs shall never lack a friend, And who in want a hollow friend doth try Directly seasons him his enemy. Hamlet W. Shakespeare
Joaquin, p <-levelplot(frame, colorkey=TRUE) print(update(p, legend=NULL), position=c(0/4,0,1/4,1), more=TRUE) print(update(p, legend=NULL), position=c(1/4,0,2/4,1), more=TRUE) print(update(p, legend=NULL), position=c(2/4,0,3/4,1), more=TRUE) draw.colorkey(p$legend$right$args$key, draw=TRUE, vp=grid::viewport(x=grid::unit(.9, "npc"), y=grid::unit(.5, "npc"), height=grid::unit(.8, "npc"))) This should get you started. In your original code the print.trellis function is leaving enough space for the legend in your third usage, hence the graph is smaller. The above code suppresses the legend all three times. That way the same space is allocated for the graph. Then the key is printed using the grid functions directly. Rich [[alternative HTML version deleted]]
Your reply was very useful Rich. Thanks! I would like to set the height of the viewport in draw.colorkey to match the height of the levelplots, as it is done when I add colorkeys to all the levelplots. The height of the levelplots varies depending on the number of levelplots that I put on the figure. Do you know of any method to obtain the height of the levelplots? Thanks again, Joaquin On Thu, Mar 25, 2010 at 04:40:13PM -0400, RICHARD M. HEIBERGER wrote:> > Joaquin, > > > > p <-levelplot(frame, colorkey=TRUE) > print(update(p, legend=NULL), position=c(0/4,0,1/4,1), more=TRUE) > print(update(p, legend=NULL), position=c(1/4,0,2/4,1), more=TRUE) > print(update(p, legend=NULL), position=c(2/4,0,3/4,1), more=TRUE) > > > > draw.colorkey(p$legend$right$args$key, draw=TRUE, > > vp=grid::viewport(x=grid::unit(.9, "npc"), > > y=grid::unit(.5, "npc"), > > height=grid::unit(.8, > "npc"))) > > > > This should get you started. In your original code the print.trellis > function is leaving enough space for > > the legend in your third usage, hence the graph is smaller. > > > > The above code suppresses the legend all three times. > > That way the same space is allocated for the graph. Then the key is > printed using > > the grid functions directly. > > > > Rich-- Joaquin Rapela PhD Student, Electrical Engineering University of Southern California 3641 Watt Way, Los Angeles, CA 90089-2520 tel/fax: (213) 821-2070 http://www-scf.usc.edu/~rapela ---------------------------------- Player King: And hitherto doth love on fortune tend: For who not needs shall never lack a friend, And who in want a hollow friend doth try Directly seasons him his enemy. Hamlet W. Shakespeare
On Fri, Mar 26, 2010 at 12:46 AM, Joaquin Rapela <rapela at usc.edu> wrote:> > I want to create a simple plot containing three levelplots with one colorbar. > I used the "Three levelplots" code below, but the third levelplot is drawn > smaller than the first two. However, if I try the "Two levelplots" code below > it works well. Can anybody tell me how could I draw three levelplots (of the > same size) with one colorbar. > > Thanks in advance, Joaquin > > ### Three levelplots ### > frame <- matrix(rnorm(16*48), nrow=16) > > p <-levelplot(frame, colorkey=FALSE) > print(p, position=c(0,0,1/3,1), more=TRUE) > p <-levelplot(frame, colorkey=FALSE) > print(p, position=c(1/3,0,2/3,1), more=TRUE) > p <-levelplot(frame, colorkey=TRUE) > print(p, position=c(2/3,0,3/3,1), more=FALSE)Just out of curiosity, if you have a common color key, why is a (single) multipanel levelplot not appropriate? -Deepayan
A single multipanel levelplot would be perfect, but from the help to wireframe I understood that conditioning was not possible when the argument to levelplot was a matrix. If it is possible please let me know.> help(wireframe) > ... > For 'wireframe', 'x', 'y' and 'z' may also be matrices (of > the same dimension), in which case they are taken to > represent a 3-D surface parametrized on a 2-D grid (e.g., a > sphere). Conditioning is not possible with this feature. See > details below.Thanks, Joaquin On Fri, Mar 26, 2010 at 05:25:38PM +0530, Deepayan Sarkar wrote:> On Fri, Mar 26, 2010 at 12:46 AM, Joaquin Rapela <rapela at usc.edu> wrote: > > > > I want to create a simple plot containing three levelplots with one colorbar. > > I used the "Three levelplots" code below, but the third levelplot is drawn > > smaller than the first two. However, if I try the "Two levelplots" code below > > it works well. Can anybody tell me how could I draw three levelplots (of the > > same size) with one colorbar. > > > > Thanks in advance, Joaquin > > > > ### Three levelplots ### > > frame <- matrix(rnorm(16*48), nrow=16) > > > > p <-levelplot(frame, colorkey=FALSE) > > print(p, position=c(0,0,1/3,1), more=TRUE) > > p <-levelplot(frame, colorkey=FALSE) > > print(p, position=c(1/3,0,2/3,1), more=TRUE) > > p <-levelplot(frame, colorkey=TRUE) > > print(p, position=c(2/3,0,3/3,1), more=FALSE) > > Just out of curiosity, if you have a common color key, why is a > (single) multipanel levelplot not appropriate? > > -Deepayan-- Joaquin Rapela PhD Student, Electrical Engineering University of Southern California 3641 Watt Way, Los Angeles, CA 90089-2520 tel/fax: (213) 821-2070 http://www-scf.usc.edu/~rapela ---------------------------------- Player King: And hitherto doth love on fortune tend: For who not needs shall never lack a friend, And who in want a hollow friend doth try Directly seasons him his enemy. Hamlet W. Shakespeare