Re: [R] Lattice: how to get default ylim?

From: David James <dj_at_research.bell-labs.com>
Date: Thu 19 May 2005 - 23:00:51 EST

Hi,

Within your panel function you can use current.viewport() to recover the active grid viewport and get xlim/ylim (in addition to other very useful information). Then you can use grid.text (plus any other grid.* function), e.g.,

  require(grid)

  my.panel <-
  function(...)
  {

     panel.xyplot(...)   

     ## add "Hello World on the top-left of each panel   

     v <- current.viewport()        ## requires R 2.1.0 (I believe)
     xlim <- v$xscale
     ylim <- v$yscale
     grid.text(x = xlim[1], y = ylim[2], default.units="native",
        label = "Hello World", just= c("left", "top"))
  }

Hope this helps.

--
David

Wladimir Eremeev wrote:

> Dear r-help,
>
> I draw graphics with xyplot and want to add some text to each panel
> (actually, the slope, error and significance of a regression line).
>
> I have defined the function, drawing a single panel and pass it to
> xyplot in the panel argument. This function calls panel.xyplot,
> calculates linear regression and formats coefficients.
>
> Now I want the text, I mentioned above, to be put in the upper left
> corner of each plot.
> I use ltext, and I need to define coordinates x and y.
> In order to do this I need to know the limits of x and y axes.
>
> I do not want to pass arguments xlim and ylim to the xyplot function
> and want it to calculate them automatically.
> And I also want to know the result of calculations. :)
> How to do this?
>
> Thank you very much.
>
> --
> Best regards
> Wladimir Eremeev mailto:wl@eimb.ru
>
> ==========================================================================
> Research Scientist, PhD Leninsky Prospect 33,
> Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071,
> Institute of Ecology, Phone: (095) 135-9972;
> Russian Academy of Sciences Fax: (095) 135-9972
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu May 19 23:18:06 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:51 EST