Skip to content
Prev 169293 / 398502 Next

lattice key inside panel

On Wed, Feb 4, 2009 at 8:21 AM, Iago Mosqueira <iago.mosqueira at gmail.com> wrote:
No. The placement controls such as x, y, and corner are not handled by
draw.key itself, but rather by the high-level plotting function. Used
directly, draw.key() basically gives you a low-level grid "grob", and
you need to use grid tools to do anything with them ('draw=TRUE'
simply calls grid.draw() on the grob before returning it). The
simplest way to change position is to supply a simple 'vp' argument.

xyplot(1~1,
       panel = function(...) {
           require(grid)
           panel.xyplot(...)
           draw.key(list(text=list(lab='catch'),
                         lines=list(lwd=c(2)),
                         text=list(lab='landings'),
                         rectangles=list(col=rgb(0.1, 0.1, 0, 0.1))),
                    draw = TRUE,
                    vp = viewport(x = unit(0.75, "npc"), y = unit(0.9, "npc")))
       })

 More complex positioning (perhaps depending on the size of the
legend) will need more work.

-Deepayan