[R] overlaying a contour line in a levelplot

Deepayan Sarkar deepayan at stat.wisc.edu
Wed Apr 20 17:13:01 CEST 2005


On Wednesday 20 April 2005 09:16, Jorge Ahumada wrote:
> Hello there,
>
> I am creating a series of images using levelplot but I also want to
> overlay a contour for a particular value as reference. Here is the
> levelplot command for the image:
>
> print(levelplot(d~x+y,data=t,cuts=20,scales=list(draw=F),xlab=NULL,yl
>ab= NULL,col.regions=heat.colors(100)[100:1]),split=c(1,1,1,1),more=T)
>
> and then to add the contour plot (I only want a contour at level 5):
>
> print(levelplot(d~x+y,data=t,cuts=20,scales=list(draw=F),xlab=NULL,yl
>ab= NULL,contour=T,at=c(0,5),reg=F,labels=F),split=c(1,1,1,1))
>
> this shifts the contourline to the right of the levelplot. If I use
> region=T then it looks better but it is still shifted slighlthy, plus
> have an extrakey overlayed to the original key with different numbers
> on it.

You are going about this all wrong. Here's the correct way (with 
different data since you haven't given us a reproducible example):

levelplot(volcano,
          panel = function(..., at, region = TRUE, contour = FALSE) {
              panel.levelplot(..., at = at,
                              region = region,
                              contour = contour)
              panel.levelplot(..., at = 140,
                              region = FALSE,
                              contour = TRUE)
          })

Deepayan




More information about the R-help mailing list