Skip to content

Trellis graphics and clipping

4 messages · (Ted Harding), Uwe Ligges, Deepayan Sarkar

#
Hi again folks,

I seem to have got the trellis (lattice + grid) business
working basically OK, in that I can get my 5x5 array of
histograms laid out as they should be.

However, there is a behaviour I can't see my way round.

Even when displayed in the R Graphics Window, there is
some clipping (the extreme top, bottom, left and right
edges are not there, so that labels, and parts of numerical
scale markers all round, have been clipped off).

When I switch to the "postscript" device, with the comamnd
'postscript(filename,...)', the result is even more clipped,
in that parts of the histogram plots themselves get cut off,
including their titles as seen in the X11 display. On the
other hand (using gv's "position meter"), it seems that the
internal %%BoundingBox matches the dimensions and coordinates
of what SHOULD get displayed/printed, allowing plenty of
"white space" round the bit of the graphic that _does_ get
displayed, so that the whole thing could have been fitted in
anyway.

And if I go at it crudely, simply using 'dev.print()' to
bang out a har-copy, it is even more clipped again ...

I've tried playing with all the obvious (to me) parameters
which I can find, but it has not effect on this.

I've checked the PostScript file itself, and the parts that
are missing are not mentioned therein, so it's not a PostScript
"clippath" phenomenon: it's definitely R which is deciding not
to output them.

What's needed is some way of coordinating the dimensions of
the various levels of this process, so that the output to X11
is scaled so that the whole graphic can fit in, and the output
to postscript is also scaled so that it fits into whatever
size of graphic is nominated (not that this should be an
issue for EPS output anyway -- it would be quite sufficient
to output everything and then put a BoundingBox round the
lot, and never mind things like papersize and so forth).

So I'm bewildered. And, if anyone knows a way round it,
I'd be most obliged to hear!

With thanks,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 29-Jul-01                                       Time: 13:40:47
------------------------------ XFMail ------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On 29-Jul-01 Ted Harding wrote:
Follow-up.

I've tried the following:

  hgm<-histogram( ~N | B , xlim=x(0,5), layout=c(5,5) , ... )

  print.trellis( hgm , position=c(0.075,0.075,0.925,0.925) )

so as to force down-scaling of the graphic, and now everything
is fully displayed in X11: top and bottom scale annotations,
bottom label and side label, and all the histograms. No clipping
whatever. No problems.

Except that there's an error message:

  Error in unset.gpar(vps[[1]]$gp) : trying to reset with 10

Next, I've done

  postscript(horizontal=FALSE,onefile=FALSE)

and again

  print.trellis( hgm , position=c(0.075,0.075,0.925,0.925) )

(getting the same error message)

and then looked at the resulting PS file. This is again slightly
clipped (on the left, as it happens, so that the left label lacks
the tops of its letters), but everything else is absolutely fine.
OK,

  print.trellis( hgm , position=c(0.1,0.1,0.925,0.925) )

(same error message).

Now, Lo and Behold, when I view the PS file there is no clipping
at all. Good!

So, apart from this error message (which must mean something, but
nevertheless goes with perfect output) all now seems fine.

But it still puzzles me that one has to grope for the correct
"position" parameter settings for each device.

Is there a way to pull all this together?

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 29-Jul-01                                       Time: 16:12:11
------------------------------ XFMail ------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Sun, 29 Jul 2001 Ted.Harding at nessie.mcc.ac.uk wrote:

            
Instead of postscript(...) you might want to use

  trellis.device("postscript", ...)


Uwe Ligges

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
The problem lies (if I get you correctly) in the fact
that Lattice graphics devices need to be initialized
differently from usual R graphics devices. This has to
do with special requirements of the underlying grid
package, and also some standard parameter settings
associated with each device.

Upshot: you need to use

trellis.device(postscript, file = "filename.ps")

instead of 

postscript("filename.ps")

What this does (with regard to clipping) is that it
calls a grid function grid.start(). You can get almost

the same effect if you do

postscript(filename)
grid.start()

but trellis.device is the preferred way. The same goes
for the x11() device.

I would encourage you to read the ?Lattice help page
to familiarise yourself with this sort of
peculiarities.

Note: Currently, usual R graphics and lattice/grid
graphics don't mix, that is, you have to enclose any
calls to grid graphics functions (which includes all
lattice graphics functions) within calls to
grid.start() and grid.stop(). Hopefully, this will
change somewhat in the next release of lattice.
--- Ted.Harding at nessie.mcc.ac.uk wrote:
--------------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._