Re: [R] Getting default aspect ratio from lattice

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Tue, 15 May 2007 13:45:12 -0700

On 5/15/07, Waichler, Scott R <Scott.Waichler_at_pnl.gov> wrote:

> How can I get the value of the aspect ratio that is used in a lattice
> plot? In a levelplot for instance, the native units per cm of my x and
> y axes are different, and I need to know the aspect ratio so that I can
> correctly plot vectors. I know how to set the aspect in a high-level
> lattice function but I can't quite figure out how to get it. I would
> like call to levelplot() without printing anything, get the aspect
> ratio, use it to create my vector arrows, then call levelplot() again
> with print() to create the final figure.

Your question doesn't necessarily have a well defined answer, because the aspect ratio may be computed only on printing (and not even then, as the aspect ratio may change after printing if you resize the device). In fact, this is the default behaviour (aspect = "fill").

The good news is that for any other value of 'aspect', you are in luck. ?trellis.object says:

     A trellis object, as returned by high level lattice functions like
     'xyplot', is a list with the '"class"' attribute set to
     '"trellis"'.  Many of the components of this list are simply the
     arguments to the high level function that produced the object.
     Among them are [...]. Some other
     typical components are:

     [...]

     'aspect.fill' logical, whether 'aspect' is '"fill"'

     'aspect.ratio' numeric, aspect ratio to be used if 'aspect.fill'
          is 'FALSE'

and we have:

> levelplot(volcano, aspect = "fill")$aspect.ratio
[1] 1

> levelplot(volcano, aspect = "iso")$aspect.ratio
[1] 0.7011494
> levelplot(volcano, aspect = 2)$aspect.ratio
[1] 2

etc.

-Deepayan



R-help_at_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 and provide commented, minimal, self-contained, reproducible code. Received on Tue 15 May 2007 - 20:52:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 May 2007 - 00:32:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.