Wladimir Eremeev
2003-Jul-21 14:50 UTC
[R] Lattice: how to draw some text outside the panel?
Dear r-help I draw plots with xyplot() function. Each plot contains also a line of regression. I want to write the trend value and its significance (obtained with lm()) below each panel. I use ltext() for this. But the text is cut, when it comes outside a panel. Moreover (obviously), it doesn't appear at all when its coordinates are outside a panel. Could you, please, be so kind to give me a direction to walk in order to have a text written below a panel. Thank you! -- Best regards Wladimir Eremeev mailto:wl at eimb.ru =========================================================================Research Scientist Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 954-5534
Hi Wladimir Eremeev wrote:> Dear r-help > > I draw plots with xyplot() function. > > Each plot contains also a line of regression. > I want to write the trend value and its significance > (obtained with lm()) below each panel. > I use ltext() for this. > But the text is cut, when it comes outside a panel. > Moreover (obviously), it doesn't appear at all when its > coordinates are outside a panel. > > Could you, please, be so kind to give me a direction to walk > in order to have a text written below a panel.Lattice clips to the panel by default. I think there is a plan to add a lattice argument to allow you to turn this clipping off in future versions. In the meantime, there is a workaround. The idea is to push a viewport bigger than the panel and set the clipping region using that larger viewport, then push another viewport which is the same as the original panel (but do not clip to that). The following example shows what to do (if you remove the push.viewport and pop.viewport bits the text is clipped to the panel): data(quakes) Depth <- equal.count(quakes$depth, number=8, overlap=.1) xyplot(lat ~ long | Depth, data = quakes, panel=function(x, y, ...) { panel.xyplot(x, y) # Set the clipping region four times larger xscale <- current.viewport()$xscale yscale <- current.viewport()$yscale push.viewport(viewport(width=2, height=2, clip=TRUE)) push.viewport(viewport(width=.5, height=.5, xscale=xscale, yscale=yscale)) ltext(rep(165, 4), seq(-10, -40, -10), c("one", "two", "three", "four")) # Pop the extra viewports (VERY IMPORTANT!) pop.viewport(2) }) Hope that helps Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/