win.metafile [RE: [R] insert eps into microsft word]

Marc Schwartz MSchwartz at medanalytics.com
Tue Oct 7 03:21:15 CEST 2003


On Mon, 2003-10-06 at 19:21, Gabor Borgulya wrote:
> 2003-09-10, sze keltezéssel David Khabie-Zeitoune ezt írta:
> > Have you tried win.metafile (I'm assuming you are using Windows)?
> > E.g.
> > 
> > win.metafile(file = "c:/test.wmf")
> > plot(rnorm(100))
> > dev.off()
> 
> Hi!
> 
> I could not run this example:
> Error: couldn't find function "win.metafile"
> 
> I am using Linux. Does this function only exist in the windows version
> of R? Why? Does it need some functions of the OS itself? Can the Linux
> version of R be invoked or compiled with a switch enabling WMF support?
> 
> Eps is perfect for a paper, but I would need the same graphs in a MS
> Power Point presentation es well. I tried OpenOffice, but it could not
> import the eps image.
> 
> Do I have to re-run my script on a windows PC?
> 
> Gabor


The WMF/EMF format is available on Windows only, since it depends upon
Windows OS functionality.

There is a WMF/EMF library for Linux (called libemf), but I can tell you
from personal experience that it does a poor job quality-wise.

There is discussion from the OpenOffice folks on the possibility of
supporting SVG format imports possibly in version 2.x, but not before
then. SVG would provide scalable vector format functionality (like WMF)
for cross-platform support. But not yet.

What I do is to generate an EPS file using R and import that in to
OpenOffice. I can then print it to a PS file and if need be, use ps2pdf
to create a PDF file version.

The trick with R in creating EPS files is to follow the instructions
under ?postscript very closely.  OpenOffice will import R's EPS files if
generated properly.

Most importantly is to set the following arguments:

horizontal = FALSE, onefile = FALSE, paper = "special"

So a call to postscript might be:

postscript("MyGraph.eps", horizontal = FALSE, 
           onefile = FALSE, paper = "special")
plot(...)
dev.off()


That being said, if you import the EPS file into OpenOffice, you will
not see the image, unless you spend the time to create an image preview,
which will be both poor quality and substantially increase the file
size. You will only see a box with an "X" in it as a place holder.

If you need to be able to actually see the slide in OpenOffice or
PowerPoint, you would be best served (under Linux) to generate a PNG
file. See ?png for more information. You need to specify the image size
for your target so that you do not have to worry about re-sizing or you
will lose image quality, since bitmap formats do not re-size well. Once
you create the PNG file, you can then import that into OpenOffice.

An alternative to the above approach would be to use bitmap(), which
accomplishes the generation of the image file a bit differently using
ghostscript. You might try both approaches to see what looks best to
your eye. YMMV.

HTH,

Marc Schwartz




More information about the R-help mailing list