[R] Problems with augPlot and for loops

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Feb 25 17:51:08 CET 2008


FAQ Q7.22 (you may not have been aware that you were using lattice).

On Mon, 25 Feb 2008, Nicola Buratti wrote:

> Dear all,
> I'm a new R user and I find myself in trouble with some of the plot
> functions.
> I'm trying to save a sequence of plots to eps files using a for loop, but I
> get only empty figures.
> In each iteration of the for loop I fit a nlme model and I'd like to plot
> its prediction of the dependent variable values.
> This is the code I'm using to plot the figures (I removed the commands I use
> to fit the model, but they are OK)
>
> postscript(file="saReg%03d.eps",onefile=FALSE)
> for (i in 1:length(names(DatasetSa))) {
>    #[...]
>     plot(augPred(DatasetGrp.fit,primary = ~R,  level =
> 0:1),title=names(DatasetSa)[i])
>    #[...]
> }
> dev.off()
>
> When I run this code I only get one empty figure even though the loop is
> executed 70 times. If I try to run the command
>
>        plot(augPred(DatasetGrp.fit,primary = ~R,  level =
> 0:1),title=names(DatasetSa)[i])
>
> outside the loop everything goes fine.
>
> I also tried to open and close a device in each loop iteration,
>
> for (i in 1:length(names(DatasetSa))) {
>        #[...]
>        fignam <- paste("SaReg",i,sep=".");
>        fignam <- paste(fignam,".eps",sep="");
>        postscript(file=fignam)
>        tempData<-augPred(DatasetGrp.fit,primary = ~R,  level = 0:1)
>        plot(tempData)
>        dev.off()
>        #[...]
> }
>
> in that case I get the correct number of eps files but they are all empty.
>
> I would really appreciate you help.
>
> Thank you,
> NB
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>

-- 
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



More information about the R-help mailing list