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

Duncan Murdoch murdoch at stats.uwo.ca
Wed Mar 15 02:44:30 CET 2006


context grey wrote:
> Hello,
> 
> 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.

You say you want a nonstandard layout, then you say you shouldn't have 
to tell R what you want.  How else would it know?

Regarding the stretching:  that's being done by whatever software is 
importing the picture.  Just tell it to preserve the aspect ratio, and 
things will be fine.  R writes the bounding box into EPS files, and 
reasonable software should be able to read it from there.

Duncan Murdoch
> 
> Thanks for any advice or insight.
> 
> .............
> 
> Here is a sketch of the code:
> 
> library(lattice)
> 
>     plt_hi[[1]] <- xyplot(thedat[,ir] ~ thedat[,ic],
>        aspect=1/1)
> ...
>     plt_hi[[2]] <- xyplot(thedat[,ir] ~ thedat[,ic],
>        aspect=1/1)
> ...
>     plt_hi[[2]] <- xyplot(thedat[,ir] ~ thedat[,ic],
>        aspect=1/1)
> 
> # 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)
> dev.off()
> 
> ______________________________________________
> R-help at 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




More information about the R-help mailing list