[R] again troubles with lattice

Deepayan Sarkar deepayan at stat.wisc.edu
Thu May 8 17:05:40 CEST 2003


On Thursday 08 May 2003 03:54 am, Wladimir Eremeev wrote:
> Dear r-help community,
>
>   Thank you for your previous answers!
>
>   Now I have strange behaviour of the lattice library funcitons.
>   They do not draw graphics in the file when called from the script.
>   I created the script file, called, for example, "a.R", containing
>   the following
>
> library(lattice);
> trellis.device(device="png",
>                filename="a.png",
>                color = FALSE,
>                bg = "white",
>                width=600,
>                height=800
>               );
>
> xyplot(ac15$value~ac15$year|factor(lon),data=ac15,
>        type="o",
>        layout=c(1,18),
>        xlab="year",
>        );
> dev.off();

You have to print the result of xyplot, which does not happen inside another 
function unless you explicitly call print().

This is obviously somewhat confusing because base R graphics does not behave 
this way, and has led to many similar questions on this list. help(xyplot) 
has:

Value:

     An object of class ``trellis''. The `update' method can be used to
     update components of the object and the `print' method (usually
     called by default) will plot it on an appropriate plotting device.


and help(Lattice) has:


Note:

     High level Lattice functions (like `xyplot') are different from
     conventional S graphics functions because they don't actually draw
     anything. Instead, they return an object of class ``trellis''
     which has to be then `print'ed. This often causes confusion when
     the high level functions are called inside another function (most
     often `source') and hence don't produce any output.


Can you suggest any other place in the documentation where explaining this 
would have helped you find it ?

Deepayan




More information about the R-help mailing list