tags:

views:

622

answers:

1

I'm trying to put multiple lattice plots in one window using levelplot by setting par(mfrow=c(2,1)) but it seems to be ignoring this.

Is there a particular function for setting multiple plots in lattice?

+5  A: 

lattice seems to often (but not always) ignore 'par', so i avoid using it (when plotting w/ the lattice package).

To place multiple lattice plots on a single page: first, create (but don't plot) the lattice/trellis plot objects, then call 'print', passing in one plot per call. That's the first of the three required arguments to 'print', the other two are 'more' which is only passed in for the first call to 'print', and 'pos' which gives the position of each plot on the page (as x-y coordinates for lower left-hand corner and upper right-hand corner, respectively, ie, a vector with four numbers.

Far easier to explain by example:

data(AirPassengers)     # a dataset supplied with base R
AP = AirPassengers      # re-bind to save some typing

# split the AP data set into two pieces so we have unique data for each of the two plots
w1 = window(AP, start=c(1949, 1), end=c(1952, 1))
w2 = window(AP, start=c(1952, 1), end=c(1960, 12))

px1 = xyplot(w1)
px2 = xyplot(w2)

# arrange the two plots vertically
print(px1, position=c(0, 0.6, 1, 1), more=TRUE)
print(px2, position=c(0, 0, 1, 0.4))
doug
See also the `split` argument to `?print.trellis` and section 5.8 of Murrell's "R graphics" http://books.google.co.uk/books?id=78P4zntHHVQC
Richie Cotton