[R] Question about c.trellis (latticeExtra)

Pascal Oettli kridox at ymail.com
Wed Mar 26 12:27:25 CET 2014


Dear r-help mailing list readers,

I am facing a problem using the "c.trellis" function from the
"latticeExtra" package, to merge 2 trellis objects (1 levelplot and 1
xyplot).

Using the following example, it works well without customizing the
y-axis of "levObj1". But when the y-axis is customized (levObj2), it
fails. The y-axis of "xyObj" becomes similar to "levObj2". Is there
any solution to this?

Best Regards,
Pascal Oettli


library(lattice)
library(latticeExtra)

set.seed(123)
grid1 <- expand.grid(x=1:10, y=1:9)
grid1$z <- rnorm(10*9, mean=4, sd=1)

grid2 <- data.frame(x=1:10, y=rnorm(10, sd=10))

# let levelplot determine the y-axis
levObj1 <- levelplot(z ~ x+y, grid1, colorkey=list(space='bottom'))

# now, let's customize the y-axis
levObj2 <- levelplot(z ~ x+y, grid1, colorkey=list(space='bottom'),
scales=list(y=list(at=1:9, labels=2^(1:9))))

xyObj <- xyplot(y ~ x, grid2, t='l')

# correct labelling for both objects
x11()
cObj1 <- c(levObj1, xyObj, layout=1:2)
update(cObj1, ylab=c("Correct y-axis", "Correct y-axis"))

# correct labelling for levelplot, not for xyplot
x11()
cObj2 <- c(levObj2, xyObj, layout=1:2)
update(cObj2, ylab=c("Correct customized y-axis", "Incorrect y-axis"))



More information about the R-help mailing list