Skip to content
Prev 154814 / 398503 Next

two lattice graphs in one object

On Tue, Sep 2, 2008 at 6:24 AM, Andreas Krause <andreas at elmo.ch> wrote:
Well, you cannot return it as a single "trellis" object. However, you
could always return it as a list with multiple "trellis" objects, and
they will just get printed one by one. You can attach print()
arguments to the objects themselves, so that takes care of the layout.
For example, try

plist <- {
    gr1 <-
        xyplot(rnorm(111) ~ runif(111), main = "Plot A",
               plot.args = list(position = c(0, 0, 1, 0.5), more = TRUE))
    gr2 <-
        xyplot(runif(111) ~ runif(111), main = "Plot B",
               plot.args = list(position = c(0, 0.5, 1, 1), more = FALSE))
    list(gr1, gr2)
}

print(plist)


Actually you will see some output on the console:
[[1]]

[[2]]

This is from the print method for lists. If you want to avoid that,
you can always set a class on the list you return and write a
corresponding print() method.

-Deepayan