[R] How to get correct proportions/bounding box for latex figure?

From: context grey <mobygeek_at_yahoo.com>
Date: Wed 15 Mar 2006 - 12:28:16 EST


I recently posted a question about my troubles with importing
a lattice/trellis figure into latex.

To recap,
The figure contains 3 scatterplots, so it should have roughly a 1:3 sort
of aspect ratio, in order to make each of the scatterplots square.
Instead, the whole figure comes out roughly square, so each scatterplot
is badly stretched. I fixed this by adding aspect=1/1 to the individual
xyplot() calls. However, the bounding box as seen from Latex is quite
incorrect - it appears that R and latex think the figure has a square
aspect ratio rather than the actual 1:3 ratio.

(The original post title was "postscript bounding box
in trellis/lattice plot is wrong ?", and was around 1 march.)

The recommended response appears to be to add the additional arguments
  width=3.0, height=1.0, horizontal=FALSE, onefile=FALSE, paper="special"
to the trellis.device(postscript...) call.

(The width/height arguments are required: without them
R gives an error

   "Error in grid.Call.graphics("L_setviewport", pvp, TRUE) :
                  Non-finite location and/or size for viewport")

Fine, but how then do I know what width and height are, and why should
I have to specify this? Unless I get them in exactly the right ratio,
the figures are going to be stretched (including the fonts, which will
not look professional)!

So, I guess I could print out the figure and get out a ruler and measure
(fortunately the scatterplots have boxes that I know
should be square,
so I could figure out the right ratio).

But this seems so antiquated, and makes me think I must be overlooking
something. R should be _telling me_ what the bounding box is (rather
than making me estimate it). R knows the bounding box because it puts
down the ink (metaphorically)... and if it did not know, it would
display on-screen figures with incorrect centering and clipping.

Thanks for any advice or insight.


Here is a sketch of the code:


    plt_hi[[1]] <- xyplot(thedat[,ir] ~ thedat[,ic],


    plt_hi[[2]] <- xyplot(thedat[,ir] ~ thedat[,ic],


    plt_hi[[2]] <- xyplot(thedat[,ir] ~ thedat[,ic],


# optionally add horizontal=FALSE, paper="special", etc. here
trellis.device(postscript, file=thefile, color=F)

print(plt_hi[[1]], split=c(1,1,3,1), more=T)
print(plt_hi[[2]], split=c(2,1,3,1), more=T)
print(plt_hi[[3]], split=c(3,1,3,1), more=F)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 15 12:47:21 2006

This archive was generated by hypermail 2.1.8 : Wed 15 Mar 2006 - 15:09:12 EST