Skip to content

lattice 3x3 plot: force common y-limits accross rows and align x-axes

5 messages · Boris Vasiliev, Bert Gunter, Duncan Mackay

#
Boris:

If I understand you correctly, you wish to set panel limits by row. I
know of no "slick" way of doing this (others may), as what is in a row
can change depending on layout and how you determine the scale for the
rows' contents may depend on the application context.

So I would do it manually: First, outside of trellis, compute your
xlim and ylim values for each row as you desire. Then issue the
trellis call, with the relation="free" component in the scales = list,
Then just use the list form of the xlim and ylim argument to xyplot
with your precomputed limits.

-- Bert
On Mon, Feb 18, 2013 at 8:40 AM, Boris Vasiliev <bvasiliev at yahoo.com> wrote:

  
    
#
Hi Boris

Just a different take on it, quick glimpse of it

library(lattice)
library(latticeExtra)

z= unique(df$subject)
df$nsub <- sapply(df$subject, pmatch, z)

  useOuterStrips(xyplot(count ~ 
nsub|treatment*risk, df, type = "h", lwd = 2, 
scales = list(x = list(at = 1:6, labels = z))))

The order can be changed by changing the order in 
z by making subject a factor in the correct order

see

http://finzi.psych.upenn.edu/R/Rhelp02/archive/43626.html

on how to change the yaxis limits. An example of 
mine (cut and paste)  for an 8x3 panel xyplot (it 
could be streamlined - i needed to change things 
as I went along to get everything in)

            par.settings =  layout.heights = 
list(panel = c(1,1,0.6,0.6,0.6,0.6,1,0.5)/sum(c(1,1,0.6,0.6,1,0.6,1,0.5)) )
                           ),
            scales   = list(x = list(alternating = FALSE,
                                     relation    = "same",
                                     rot         = 0),
                            y = list(alternating = FALSE,
                                     relation    = "free",
                                     limits = 
list(c(-1500,30000),c(-1500,30000),c(-1500,30000),  #  BZ
                                                   c(-1500,30000),c(-1500,30000),c(-1500,30000), 
#  LV
                                                   c(-2000,20000),c(-2000,20000),c(-2000,20000), 
#  L2
                                                   c( 
-500, 4000),c( -500, 4000),c( -500, 4000),  #  CL
                                                   c(-2000,20000),c(-2000,20000),c(-2000,20000), 
#  OP
                                                   c(-2000,20000),c(-2000,20000),c(-2000,20000), 
#  AB
                                                   c(-1500,30000),c(-1500,30000),c(-1500,30000), 
#  MO
                                                   c(-500, 
4000),c(-500,  4000),c(-500,  4000)), #  MX
                                     at = rep(list(seq(0,30000,10000), NULL,
                                                   seq(0,30000,10000), NULL,
                                                   seq(0,20000,10000), NULL,
                                                   seq(0, 4000, 2000), NULL,
                                                   seq(0,20000,10000), NULL,
                                                   seq(0,20000,10000), NULL,
                                                   seq(0,30000,10000), NULL,
                                                   seq(0, 4000, 2000), NULL ),
                                                    c(1,2, 
1,2, 1,2, 1,2, 1,2,  1,2, 1,2, 1,2) ),
                                     labels = 
rep(list(as.character(seq(0,30,10)), NULL,
                                                       as.character(seq(0,30,10)), 
NULL,
                                                       as.character(seq(0,20,10)), 
NULL,
                                                       as.character(seq(0, 
4, 2)), NULL,
                                                       as.character(seq(0,20,10)), 
NULL,
                                                       as.character(seq(0,20,10)), 
NULL,
                                                       as.character(seq(0,30,10)), 
NULL,
                                                       as.character(seq(0, 
4, 2)), NULL ),
                                                       c(1,2, 
1,2, 1,2, 1,2, 1,2,  1,2, 1,2, 1,2) ),
                                     rot         = 0)
                       ),

I had different panel heights for each row  so if 
they were all the same it would be

panel = rep(1,n)/n

the trick is to get the rep of the lists to match 
what would normally happen for each of the all 
the panels ie whether an axis/label is required

str(plot object) can help if problems

HTH

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
At 12:22 19/02/2013, you wrote: