[R] two lattice graphs in one object

Andreas Krause andreas at elmo.ch
Tue Sep 2 15:24:26 CEST 2008

When I create a lattice/Trellis type graph, I typically write a function that returns the graph, as in
do.graph <- function(x, y, ...)
    return(xyplot(y~x, ...))

My question today is this: 
If I want two graphs on one page, one way of achieving it is to print the objects into defined areas, as in

gr1 <- xyplot(rnorm(111) ~ runif(111))
gr2 <- xyplot(runif(111) ~ runif(111))
print(gr1, pos=c(0, 0, 1, 0.5), more=T)
print(gr2, pos=c(0, 0.5, 1, 1), more=F)

Instead of using the print method, can I create a single trellis object that contains those two "sub-graphs"?
I do not think so, given what I know about the design of these objects. 
I am hoping for a pleasant surprise though.


More information about the R-help mailing list