[R] add single contour line to levelplot

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Tue Aug 31 22:39:01 CEST 2004



Ian Jonsen wrote:

> Hello,
> 
> I want to add a single contour line to a levelplot but can't figure out
> how to do it 'on-the-fly'. When I include the last line in the code below,
> I get the following error:
> 
> Error in NextMethod("[") : Argument "subscripts" is missing, with no default
> 
> Any tips on how to fix this are greatly appreciated!
> 
> Ian Jonsen
> 
> 
> levelplot(dens~nu*sigma,data=tsurflikB,at=c(-20,-10,-5,-4,-3,-2,-1),
>  col.regions=gray(seq(0.5,0.9,length=14)),region=T,colorkey=F,aspect=1,
>  panel=function(x,y,z,...){
>       panel.levelplot(x=x,y=y,z=z,...)
>       lpoints(x[z==0],y[z==0],pch=16,cex=0.5)
>       panel.levelplot(z~x*y,at=-3,contour=T,aspect=1)
>  }
> )
> 

You have misued panel.levelplot and also forgot (neglected?) to include 
"..." in the second call. I think you want something like:

# from ?levelplot
library(lattice)
x <- seq(pi/4, 5 * pi, length = 100)
y <- seq(pi/4, 5 * pi, length = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x = x, y = y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z ~ x * y, grid, cuts = 50, scales=list(log="e"),
           xlab = "", ylab = "", main = "Weird Function",
           sub = "with log scales",
           panel = function(x, y, z, at, contour, ...) {
             panel.levelplot(x, y, z, at = 0, contour = TRUE, ...)
             lpoints(x[z <= -0.5],y[z <= -0.5], pch = 16, cex = 0.5)
           },
           colorkey = FALSE, region = TRUE)

Note the usage of "...". I also think you do not need two calls to 
panel.levelplot, though I may be misunderstanding your intention. One 
will suffice, as it does here.

--sundar




More information about the R-help mailing list