# [R] superposing lattice plots

jiho jo.irisson at gmail.com
Fri Aug 17 16:25:27 CEST 2007

```Hello everyone,

I am sorry if this has already been asked but I can't find it. I want
to superpose two lattice plots, namely a levelplot and a contourplot
of two different variables with the same x-y scale. I found
information about panel.superpose but it does not seem to correspond
to what I want (I have two different variables, not groups of the
same variable)

How can I do this? Is there a way to concatenate the two trellis
objects and plot that?

Simple example using simulated data:

x=seq(-5,5,length.out=100)
y=seq(-2,2,length.out=60)
mat1=cos(x)%*%t(cos(y))
mat2=cos(x)%*%t(sin(y))
levelplot(mat1)
contourplot(mat2)

I would like both plots to appear superposed.

PS: accessory question, for the enthusiast ;). When data in contained
in a matrix and x-y coordinates in separate vectors, as above, is
there a way to get level/contourplot to use x and y as the
coordinates vectors other than by "unrolling" the matrix in a
data.frame:
x	y	mat
1	1	0.125
1	2	0.1367
1	3	0.2345
....
and using mat ~ x*y ?