Re: [R] Getting eps into Word documents.

From: Marc Schwartz (via MN) <mschwartz_at_mn.rr.com>
Date: Wed 05 Oct 2005 - 03:42:17 EST

On Tue, 2005-10-04 at 08:38 -0500, Robert Baer wrote:
> > > On 03-Oct-05 Marc Schwartz (via MN) wrote:
> > > > On Mon, 2005-10-03 at 16:31 -0300, Rolf Turner wrote:
> > > >> A student in one of my courses has asked me about getting R graphics
> > > >> output (under Linux) into a Word document. I.e. she wants to do her
> > > >> R thing under Linux, but then do her word processing using Word.
> --------------snip--------------
> > > > So use something like the following:
> > > >
> > > >
> > > > postscript("RPlot.eps", height = 4, width = 4,
> > > > horizontal = FALSE, onefile = FALSE,
> > > > paper = "special")
> > > >
> > > > plot(1:5)
> > > >
> > > > dev.off()
> > > >
> > > >
> > > > You can then import the .eps file into Word or most other such
> > > > applications that can import encapsulated postscript files.
>
> -------------snip----------------
> > > > More information is available from MS here:
> > > >
> > > > http://support.microsoft.com/?kbid=290362
> > > >
> > > > HTH,
> > > >
> > > > Marc Schwartz
> ----------snip-----------
> > > b) It won't work anyway if printed to a non-PostScript printer.
> >
> > True, which is the case irrespective of Word/Windows. If you don't have
> > a PS printer locally or accessible via network, you can always install a
> > PS printer driver and print to a file, which can then be printed by a
> > third party if required.
> >
> Well, as a lowly Windows and Office user, I most often right click on R
> grahics, cut to clipboard, and paste into Word. So one possiblility is for
> the student to install R on her own machine (Windows or Mac?).
>
> But I just tried Marc's suggestion, and it looks VERY VIABLE to me. I
> generated the graph from his code snippet and used "Insert picture from
> file" in Word 2003 to place the graphic in a Word document. I then tried
> printing on both an HP 4100 TN laserjet and an HP 960c deskjet. The image
> printed perfectly on both printers with crisp lines and text that apprear to
> be vector-based not degraded bitmapped representations. Certainly worth the
> student trying.

Glad to hear that worked for you.

I do think that the majority of problems with importing EPS files from R into other applications (Word, Powerpoint, Writer, Impress, etc.) are due to not properly configuring the postscript() arguments that are on the help page.

I should also note that beyond plots, I use this same approach for putting LaTeX tables into these documents as well. There are times where I need create one or more nicely formatted tables for inclusion in another document, to then be used by someone else.

I generate the LaTeX preamble, document and table code using R, then run:

  latex FileName.tex
  dvips -E FileName -o FileName.ps

where the '-E' option to dvips attempts to create an EPS output file with a tight bounding box. The result is a single EPS file with the table (much like the plot example) ready for import.

I had been using 'epstool' to create the image preview, but now that OO.org 2.0 has included this automatically upon import (as do the latest versions of Word), this step is no longer required.

In this way, I can use R to create reproducible and publication ready tables for use by others in their documents, in situations where they are not (or cannot) use LaTeX for the entire document.

HTH, Marc



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 Oct 05 03:48:10 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:17:54 EST