[R] levelplot and contour lines

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Jun 10 20:03:41 CEST 2010


On Thu, Jun 10, 2010 at 9:30 PM,  <rchandler at nrc.umass.edu> wrote:
> Hello list,
>
> Is there a way to add contour lines to a levelplot at different breakpoints
> than are used for the colors? For example:
>
>
> library(lattice)
>
> # colors good but too many contours
> levelplot(volcano, at=94:195, contour=TRUE)
>
> # I thought something like this might work
> levelplot(volcano,
>    panel=function(...) {
>        panel.levelplot(..., at=94:195)
>        panel.contourplot(..., at=c(100, 125, 150))
>        })

Something like that does work, you just need to capture and modify the
relevant arguments:

levelplot(volcano,
   panel=function(..., at, contour, region) {
       panel.levelplot(..., at=94:195, contour = FALSE, region = TRUE)
       panel.contourplot(..., at=c(100, 125, 150), contour = TRUE,
region = FALSE)
       })

Unless you capture the arguments explicitly, they get supplied to
panel.contourplot etc. twice, once when you explicitly specify it, and
once as part of the ...-s.

-Deepayan



More information about the R-help mailing list