[R] Location of grobs etc on lattice output

John Maindonald john.maindonald at anu.edu.au
Sun Nov 21 02:41:49 CET 2004


Is there any way, after use of print.trellis(), to obtain the
co-ordinates of the plot region, e.g., in what are then the
native co-ordinates?

e.g.
  library(DAAG)
  library(lattice); library(grid)
  data(cuckoos)
  pushViewport(viewport(layout=grid.layout(2, 1)))
  pushViewport(viewport(layout.pos.row=1))
  cuckoos.strip <- stripplot(species ~ length, data=cuckoos)
  print(cuckoos.strip, newpage=FALSE)
  grid.text("A", x=unit(0.18,"native"), y=unit(0.925,"native"))
   # This works, but is fiddly, and needs rejigging if width
   # or fontsize are changed.
  popViewport(1)

An alternative would of course be to access the co-ordinate
system used by the lattice function for locating the panels,
or for locating labelling.

As in the example above, I have been using grid.text() to
position text outside the plot region, but closer to the "top"
axis than the legend parameter to the lattice function will
allow.

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.




More information about the R-help mailing list