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

Ajay Shah ajayshah at mayin.org
Sun Feb 22 16:43:37 CET 2004


It was pointed out that while 

win.metafile("/myfile.wmf")

is useful, it only works on windows.

Here's a path which would work on Unix:

1) Write an xfig file using R. I use something like :

   xfig(file="created.fig", onefile=TRUE, bg="LightSkyBlue", width=5, height=3)
   plot()

   This is a very smart path to take if you want to manually touch up
   the picture in xfig (leave aside the Windows problem).

2) The program fig2dev converts .fig files into many file formats,
   including one "cgm" which is reputed to feed well into Microsoft
   software. I have no Windows here, however, and can't try this out.


Now for a (perhaps trivial) question: Several people said you have to
do

  win.metafile("/myfile.wmf")
  plot(1:10)
  dev.off()                 <--------  this is essential

Why is the 3rd line essential? I have been feeding R programs into R
using the command

$ R --vanilla < file.R

and I find things work just fine without having a dev.off()
command. E.g. I have this program which seems to work fine:

  A <- read.table(
         file="datafile.2",
         na.strings=".",
         col.names=c("date","dlinrchf","dlusdchf","dljpychf","dldemchf")
       )
  xfig(file="created.fig", onefile=TRUE, bg="LightSkyBlue", width=5, height=3)
  plot(A$dlusdchf, A$dlinrchf,
                   xlab="USD/CHF returns",
                   ylab="INR/CHF returns",
                   col = "dark red")

     -ans.

-- 
Ajay Shah                                                   Consultant
ajayshah at mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi




More information about the R-help mailing list