[R] R: Including R plots in a Microsoft Word document

Frank E Harrell Jr feh3k at spamcop.net
Fri Feb 20 18:29:24 CET 2004


On Fri, 20 Feb 2004 11:08:00 -0600
Marc Schwartz <MSchwartz at medanalytics.com> wrote:

> On Fri, 2004-02-20 at 09:54, Mahmoud K. Okasha wrote:
> > Greetings List,
> > 
> > I am conducting some large simulations using R. As a result, I get
> > many plots but I'm having some trouble with including some of them in
> > a Microsoft Word document. Can any one tell me the easiest method of
> > having copies of the R-graphs in the Word documents?
> > 
> > Best regards
> > Mahmoud
> 
> 
> A couple of different ways:
> 
> 1. If you actually need to see the graphics within the document and/or
> send the .doc file to someone who needs to be able to see the plots as
> they appear, then you should use Windows Metafile format images. Since
> these are vector format files, you can resize them as required on your
> pages. Bitmapped images (ie .BMP/.PNG) will distort as you resize them.
> You can generate these by plotting directly into an R plot window and
> then copy (ie. right mouse click) and paste into the Word document using
> the Windows clipboard, or generate the plot files directly using the
> win.metafile() function.
> 
> 2. If you will be generating hard copies of the documents using a PS
> printer, you can generate the graphics as EPS files using the
> postscript() function. Word can import EPS files, but you will see them
> only as place holders in your document (ie. a frame box) since Word
> cannot actually interpret the images for display. Keep in mind that the
> function has very specific argument requirements to enable the
> generation of EPS files. These include:

Newer versions of Word will display postscript and pdf images on-screen,
so I think these are the way to go. -Frank

> 
> horizontal = FALSE, onefile = FALSE, paper = "special"
> 
> With these in place, you can then generate your plots to the EPS files
> and import them into your Word documents.
> 
> See ?postscript for more information.
> 
> If this is something that you will be doing with a level of repetition,
> you might want to look into using Sweave, which combines LaTeX and R to
> automate formatted report generation. More information is here:
> 
> http://www.ci.tuwien.ac.at/~leisch/Sweave/
> 
> There were also a couple of articles in RNews:
> 
> Friedrich Leisch. Sweave, part I: Mixing R and LaTeX. R News,
> 2(3):28-31, December 2002.
> 
> Friedrich Leisch. Sweave, part II: Package vignettes. R News,
> 2(2):21-24, October 2003.
> 
> 
> Frank Harrell also has a document at:
> 
> http://cran.r-project.org/doc/contrib/Harrell-statcomp-notes.pdf
> 
> HTH,
> 
> Marc Schwartz




More information about the R-help mailing list