Skip to content
Prev 59522 / 398502 Next

Location of grobs etc on lattice output

I'm puzzled about side effects of trellis.unfocus():

The following runs without problem, though grid.text() does not
seem to do anything.  (I'd thought that I had it working at one point.)

     library(DAAG); library(lattice); library(grid)
     cuckoos.strip <- stripplot(species ~ length, xlab="", data=cuckoos)
     cuckoos.bw <- bwplot(species~length, xlab="Length of egg (mm)",
                          data=cuckoos)
     vp0 <- viewport(layout=grid.layout(2, 1))
     pushViewport(vp0)
     vp1 <- viewport(layout.pos.row=1)
     vp2 <- viewport(layout.pos.row=2)
     pushViewport(vp1)
     print(cuckoos.strip,newpage=FALSE)
#   trellis.focus("panel", row=1, column=1, clip.off=TRUE)
     grid.text("A", x=unit(0,"native"), y=unit(1.05,"native"),
               gp=gpar(fontsize=9))
#   trellis.unfocus()  ## & remove the following upViewport()
     upViewport()
     pushViewport(vp2)
     print(cuckoos.bw, newpage=FALSE)
     trellis.focus("panel", row=1, column=1, clip.off=TRUE)
     grid.text("B", x=unit(0,"native"), y=unit(1.05,"native"),
               gp=gpar(fontsize=9))
     trellis.unfocus()

If I remove the #'s, and remove the upViewport() that
follows the second #, I seem to lose the current tree,
as though the newpage=FALSE for the next print()
is ignored.  Should I be able to do something like this?
Clearly I do not understand what happens when
trellis.focus() is invoked.

This seems an area where an effective GUI, with a
graphical display of the viewport tree, could be very
helpful.

John Maindonald             email: john.maindonald at anu.edu.au
phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
Centre for Bioinformation Science, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.
On 21 Nov 2004, at 3:41 PM, Deepayan Sarkar wrote: