[R] multiple lattice, xyplot & levelplot on same page

Ky Mathews k.mathews at usyd.edu.au
Sat Sep 26 12:19:03 CEST 2009


Dear R-users,

I'd like to place an xyplot() at the top of a page and a levelplot() at the bottom of the same page, and have the x-axes be the same.

I've come close to finding a solution through Rarchive, and can produce an upside-down version of what I'd like (levelplot() on the top - see code below).

However, the following error occurs when I try and plot the xyplot() at the top:

"Error in prepanel.default.function(x = 0:10, y = c(0, 1, 4, 9, 16, 25,  :
  element 1 is empty;
   the part of the args list of 'length' being evaluated was:
   (subscripts)"

Any pointers in the right direction would be much appreciated.

#OS: Windows XP 2002 SP3; R: 2.9.2; lattice 0.17-25; latticeExtra 0.6-1

Thanks and regards,
Ky

###########################################################
#Rcode for xyplot and lattice plot on the same page.
library(lattice)
library(latticeExtra)
 
 #xyplot
 x1 <- 0:10
 x2 <- x1^2
 
 p1 <- xyplot(x2 ~ x1
          , par.settings = list(layout.width = list(panel=1,  ylab = 2
          , axis.left =1.0, left.padding=1
          , ylab.axis.padding=1, axis.panel=1)))
 
 
 #levelplot
 y.df <- data.frame(y1 = rep(x1, times = 3)
                  , y2 = rep(c('E1', 'E2', 'E3'), each = length(x1))
                  , y3 = c(x1, x1+2, x1-1))
 p2 <- levelplot(y3 ~ y1*y2, data = y.df,
                , par.settings = list(layout.width = list(panel=1,  ylab = 2
                , axis.left =1.0, left.padding=1
                , ylab.axis.padding=1, axis.panel=1)))

#Printing the plots on the same page 
#This is what I found on an Rarchive post (thank-you)
 #it works if the levelplot (p2) is at the top of the page
 #i.e.
  update(c(p1, p2, x.same = TRUE)
           , layout = c(1, 2)
           , ylab = list(c("p1", "p2")
           , y = c(1/4, 3/4))
           , par.settings = list(layout.heights = list(panel = c(1, 1))))

 #however, the following error appears if the order is reversed (which is what I would like)
 update(c(p2, p1, x.same = TRUE)
           , layout = c(1, 2)
           , ylab = list(c("p2", "p1")
           , y = c(1/4, 3/4))
           , par.settings = list(layout.heights = list(panel = c(1, 1))))

The following error appears:
#Error in prepanel.default.function(x = 0:10, y = c(0, 1, 4, 9, 16, 25,  :
#  element 1 is empty;
#   the part of the args list of 'length' being evaluated was:
#   (subscripts)

Also, I seem to have lost control of par settings such as las = 1

#-----------------------------------------------------------
Dr Ky L. Mathews
Co-ordinator, CIMMYT ICARDA Communications Project
Research Fellow,
Plant Breeding Institute, The University of Sydney, Australia




More information about the R-help mailing list