Skip to content

levelplot add line

6 messages · Deepayan Sarkar, Jeff Jorgensen

#
R folks,

I can't seem to find the instructions in the help files for the lattice 
package that explain how to add lines, such as with lines() or ?, to a 
levelplot.  I'd be grateful if someone could point me in the proper direction.

Cheers,

Jeff

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jeff Jorgensen

Center for Limnology                             jcjorgensen at wisc.edu
University of Wisconsin Madison           ph (608) 263-2304
680 North Park Street                           fx (608) 265-2340
Madison, Wisconsin 53706                http://limnology.wisc.edu

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
On Tuesday 24 February 2004 18:03, Jeff Jorgensen wrote:
The general rule for all lattice functions is to write your own panel 
function. For example, 

data(volcano)
levelplot(volcano, 
          panel = function(...) {
              panel.levelplot(...)
              panel.abline(c(0,1))
          })

lines() will not work for lattice, but you can use llines() instead. 

Of course, for anything more useful than this example, your panel function 
should make use of the data that's passed to the panel function. Exactly 
what would be passed depends on the function in question. For levelplot, 
the best place to look will be panel.levelplot, and similarly for other 
functions.

Hth,

Deepayan
#
Deepayan,

Thanks for the quick response.  Just to make sure I understand, let me 
explain in a bit more detail what I am trying to do.

I have created a levelplot (with contour lines and colored regions), and 
what I am trying to figure out now is how to add a series of horizontal 
lines across the levelplot and also assign values or labels to the lines on 
the alternative y-axis.  Would I do this with the route you suggest below?


Thanks so much for the help,

Jeff
At 06:51 PM 2/24/2004 -0600, you wrote:
#
On Wednesday 25 February 2004 08:13, Jeff Jorgensen wrote:
For adding the lines, yes. Take a look at ?panel.functions and ?llines.

I'm not sure what you mean by 'assign values or labels to the lines on the 
alternative y-axis'. As a general rule, panel regions are 'clipped', i.e., 
any attempt by the panel function to draw outside the panel has no effect. 
This can be overridden by with lset(list(clip = list(panel = FALSE))), but 
I wouldn't recommend using it unless you know what you are doing.

Deepayan
#
Thanks for putting me on the right track.  Sorry to be bothersome with 
another follow-up, but the code that calls the panel function (see below) 
doesn't seem to be working.  What am I doing wrong?

Thanks,

Jeff

levelplot(matrix,contour=T, cuts=15,at=seq(...), labels=T, region=T,
                             scales=list(x=list(at=xlocations,labels=as.character(xlabels)),
                                         y=list(at=ylocations, 
labels=as.character(ylabels))),
                             xlim=c(1:368), ylim=c(1:31),
                             colorkey = list(space = "bottom",
                                             labels = list(at = 
seq(0,2000,200),
                                             lab = seq(0,2000,200))), #If I 
cut it off here, it works fine
         panel=function(x,y,z){
                             panel.levelplot(x=c(...), y=c(...), z=matrix,
                             cuts=15,at=seq(...), contour=T, labels=T,
                             region=T,
                             subscripts=seq(...),
                             col.regions=cm.colors(100),
                             zcol=c(1:100),
                             panel.abline(h=200))
             })
At 08:34 AM 2/25/2004 -0600, you wrote:
1 day later
#
On Wednesday 25 February 2004 14:00, Jeff Jorgensen wrote:
You are using this wrong. In particular I'm completely confused by the 
c(...) usage.

You probably want something like

          panel = function(...) {
              panel.levelplot(...)
              panel.abline(h = 200)
          }

since you are not using any of the arguments passed to the panel function 
for the panel.abline call. If you do need to use something, say x, y, and 
z, your usege should be:


          panel = function(x, y, z, ...) {
              panel.levelplot(x = x, y = y, z = z, ...)

              ## do something with x,y,z
              hloc = foo(x, y, z)
              panel.abline(h = hloc)
          })


Deepayan