Re: [S] printer control

Bill Venables (wvenable@attunga.stats.adelaide.edu.au)
Fri, 20 Feb 1998 10:04:46 +1030


Keith Nieforth writes:
> Hello,
>
> This may be a basic question, but I am stumped.....
>
> I have a function to plot individual curves, 25 plots per page:
>
> function(dataset)
> {
> par(mfrow=c(5,5))
> id <- unique(dataset$id)
> for(i in id)
> plot(dataset[dataset[,'id']==i,'time'],
> dataset[dataset[,'id']==i,'result'])
> }
>
> how do I set my function up to print one page (screen) at a time?
>
> version 3.4 Release 1 for HP9000 series HP-UX 9.0.5.

Within the paradigm you have adopted one way might be

function(dataset)
{
par(mfrow=c(5,5))
id <- unique(dataset$id)
m <- 0
for(i in id) {
plot(dataset[dataset[,'id']==i,'time'],
dataset[dataset[,'id']==i,'result'])
m <- m + 1
if((m %% 25) == 0) dev.print()
}
if((m %% 25) != 0) dev.print()
invisible(NULL)
}

(The last line simply gives the function a suitably unintrusive
return value.)

What I really wanted to say, however, is that even though people
complain about how cumbersome it can be to use Trellis graphics,
I find there are many cases where Trellis is much simpler than
traditional graphics alternatives like the above. For example I
would use something like the following for this kind of problem:

trellis.device(postscript, file = "curves.ps", horizontal = F, color = T)
xyplot(result ~ time | id, data = dataset)
dev.off()

and that's just about it. Send the file to the printer at your
leisure. To inspect it before doing so you can use a previewer,
e.g.

! ghostview curves.ps

This method will enforce a uniform axis system for all plots, but
in most cases that will be what is really wanted anyway. There
may be some tailoring needed to enforce 25 plots per page &c &c,
but by and large this will not only look better than the above
traditional version, it will be labelled better and it will make
much more efficient use of what Doug Bates calls "the plotting
real estate": the page won't be gummed up with many, many copies
of the axis system and labels.

Just a mild suggestion.

Bill Venables.

-- 
Bill Venables, Head, Dept of Statistics,    Tel.: +61 8 8303 5418
University of Adelaide,                     Fax.: +61 8 8303 3696
South AUSTRALIA.     5005.   Email: Bill.Venables@adelaide.edu.au
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news