[R] lattice cloud and conditional axis limits

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Sep 13 01:34:10 CEST 2006

On 9/12/06, Karl Ove Hufthammer <karloh at mi.uib.no> wrote:
> I'm using the 'cloud' function in the 'lattice' package to produce
> multi-panel 3D scatter plots. The range of the values used vary much
> between each panel (especially on the z axis), so I wish the axis limits
> to be calculated based on the (conditional) data.
> Here's a minimal example:
> library(lattice)
> z=1:200
> x=runif(200)
> y=runif(200)
> s=factor(rep(c(1,2),each=100))
> cloud(z~x*y|s,scales=list(arrows=FALSE))
> On the first panel, the z values are in the range [1,100], and on the second
> panel, they are in the range [101,200]. I wish the z axis to reflect this,
> i.e., to only span these values. (In my actual data sets, this does make
> more sense than in this example.) If 'cloud' worked the same way the
> 'xypanel' function does, one of the following would work:
> cloud(z~x*y|s,scales=list(arrows=FALSE,z=list(relation="free")))
> cloud(z~x*y|s,scales=list(arrows=FALSE,relation="free"))
> However, it does not. Any ideas how I can make it work?

There's no direct support, but you can write a small panel function
with more or less the desired effect:

cloud(z ~ x * y | s, scales = list(arrows=FALSE),

      panel =
      function(x, y, subscripts, z, ..., zlim) {
          zlim <- range(z[subscripts], na.rm = TRUE)
          panel.cloud(x, y, subscripts, z, ..., zlim = zlim)

This is for z only, x and y should work similarly. A general solution
is possible, but I don't think the benefits justify the amount of work
required (patches are welcome, of course).


> --
> Karl Ove Hufthammer
> E-mail and Jabber: karl at huftis.org

More information about the R-help mailing list