[R] 0 margin for creating eps files

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue May 27 23:06:01 CEST 2003

On Tue, 27 May 2003, Duncan Murdoch wrote:

> On Tue, 27 May 2003 20:33:05 +0100 (BST), you wrote in message
> <20030527193305.52325.qmail at web41101.mail.yahoo.com>:
> >Dear all,
> >
> >I am trying to create eps files of R plots (in Linux) so that I can import them into Word
> >(obviously in MS Windows). What I would like is for the files to be cropped so that there is no
> >margin around the actual plot, because I have no way of editing the files after they have been
> >created. I have tried using
> >
> >par(mai=c(.75,.75,0,0))
> >
> >in order to reduce the margin; it works fine when I create a plot on the screen, however when I
> >use
> >
> >dev.copy2eps(file="FILENAME.eps")
> >
> >to save to the eps file, the margin has returned. Could someone please tell what I am doing wrong,
> >should I be using different parameter to set the margins of the eps files.
> >
> >Any help would be greatly appreciated.
> I think the easiest way to do this is to use Ghostview to "convert to
> EPS", and have it recalculate the bounding box as it does so.  Since
> it's working with a Postscript interpreter, it does the bounding box
> calculation very accurately; playing around with margins is likely to
> lead to inconsistencies depending on labels, etc.

I don't see any need for that in my examples: R did the calculation
right to the nearest bp (and that's the accuracy of bounding boxes).

I suspect you mean GSView (on Windows): ghostview (a Unix program) does 
not AFAIK have that option.

If you just want a tight bounding box, gs's bbox device will give it to 
you.  On Unix, 

gs -sDEVICE=bbox -dBATCH -dNOPAUSE -q file.eps

will do something like

%%BoundingBox: 0 0 278 283
%%HiResBoundingBox: 0.000000 0.000000 277.992018 282.023991

just copy the first one into the file.  That's how all the figures in my 
books are included, for example.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list