[R] lattice: simultaneously control aspect & outer whitespace

Jacob Wegelin
2009-08-07T18:32:46Z

Suppose we wish to achieve the following three aims:
(1) Control the aspect ratio of our plot (i.e., tweak this till it looks
great)

(2) Save the plot as a PDF with zero or minimal white space outside it.

(3) Preserve this in code, so that in the future the exact same plot can be
reproduced by simply sourcing the code.

I can almost achieve (1) and (2) on my MacBook Pro by pointing and clicking,
as follows:

   •   Start with graphics.off().

   •   Generate the plot  on the computer screen; then the outer margins are
pretty thin by default.

   •   Use the mouse to adjust the aspect ratio until it looks right.

The fact that I pointed and clicked precludes (3).

If, to avoid point-and-click, I attempt to control the aspect ratio with the
"aspect" argument to xyplot, then a large whitespace appears outside
the
graphic in the plot on my computer screen. This whitespace is carried over
to the saved *.pdf file.

If, instead of first creating the graphic on the computer screen and then
saving it, I create it in a postscript graphics device,

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

then the right outer margin is zero. That is, the graphic ends exactly at
the rightmost border of the box around the plot. But the bottom, left, and
top contain extra whitespace outside the graphic region.

Specifying

   par(oma=rep(0,4))
   par(mar=rep(0,4))

after opening the Postscript device appears to have no effect
whatsoever on this.

What is the right approach? It would be nice to be able to specify both the
aspect ratio and the amount of whitespace outside the plot, and then let the
software compute the necessary dimensions of the graphic device that are
necessary to accomodate these specs.

Thanks for any ideas

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwegelin@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

	[[alternative HTML version deleted]]