[R] contour lines on levelplot?

Spencer Graves spencer.graves at pdf.com
Mon Jun 7 03:40:29 CEST 2004


      With "image" and "contour", one can get both colors and lines to 
enhance the image of a contour plot.  What's the best way to do this 
with Lattice graphics?  The following is one ugly hack, producing the 
desired result after much trial and error (R 1.9.1 alpha under Windows 
2000): 

# setup
DF <- expand.grid(x=1:3, y=1:3)
DF$z <- (DF$x+DF$y)

# Traditional "base" graphics: 
image(x=1:3, y=1:3, z=array(DF$z, dim=c(3,3)))
contour(x=1:3, y=1:3, z=array(DF$z, dim=c(3,3)), add=T)

# Lattice hack: 
lvlplt <- levelplot(z~x*y, DF)
cont <- contourplot(z~x*y, DF)
print(lvlplt, more=T)
print(cont, position=c(0, 0, 0.9055, 1))

##################
      By comparison, the same ugly hack in S-Plus required 0.952 instead 
of 0.955.  Is this the best we can currently get with a modest effort? 

      Thanks,
      spencer graves




More information about the R-help mailing list