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(); The structure of ac15 data frame is like following year value lon 1979 93.428747 0 1979 87.298608 20 1979 78.506340 40 ... 1979 45.567890 340 1980 60.815289 0 1980 49.630904 20 1980 24.981362 40 ... I execute command source("a.R") it works and after its running I've got file a.png in the working directory. But it contains only white background field and no graphs. If I try copy commands of the script in clipboard and paste them to the R console the graphs appear in the file. -- Best regards Wladimir Eremeev mailto:wl at eimb.ru
On Thu, 8 May 2003, 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 followingThey do when called from a script running directly. It's calling the script file from source() that gives the problem. You haven't actually asked for anything to be plotted! xyplot returns a plottable object, which when *printed* is plotted. Auto-printing works at the top level in R, but not inside source. You need to wrap your lattice calls in print(). [...]> I execute command source("a.R") it works and after its running I've > got file a.png in the working directory. But it contains only white > background field and no graphs. > > If I try copy commands of the script in clipboard and paste them to > the R console the graphs appear in the file.And that is `running the script'. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
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
It might be helpful to include a brief comment on the need for an implicit or explicit call to print() in the information that is displayed by typing help(package=lattice) It might be an extra sentence under Description:> Date: Thu, 8 May 2003 10:05:40 -0500 > From: Deepayan Sarkar <deepayan at stat.wisc.edu> > Subject: Re: [R] again troubles with lattice > To: Wladimir Eremeev <wl at eimb.ru>, r-help at stat.math.ethz.ch > >..... > > Can you suggest any other place in the documentation where explaining this > would have helped you find it ? > > DeepayanJohn Maindonald email : john.maindonald at anu.edu.au Centre for Bioinformation Science, phone : (6125)3473 c/o MSI, fax : (6125)5549 John Dedman Mathematical Sciences Building (Building 27) Australian National University Canberra ACT 0200 Australia