I use R to make neat graphs that I use in Microsoft Office documents. According to this page, the best quality is obtained with the PDF driver. Unfortunately, Word doesn't support importing PDF figures. What should I use?
If you are working on a PC, it is quite convenient to insert figures into Office documents in emf format via the clipboard.
emf is a windows native vector graphics format and it allows you to edit the figures with MS Office tools. It's not perfect but it's a quick way of generating a simple report.
If your documents are at all complicated, MS Word handling of figures is horrible.
Depends on how you will be using your Word documents and what types of figures you wish to include in the document.
If the figures are standard R plots with a moderate number of points/data, then vector-based formats will provide the best reproduction and allow for easy rescaling of image size whilst having small filesize. EPS via
postscript(...., onefile = FALSE, paper = "special") in such cases would be the best format if you're outputting to a PDF or printing on a laser printer that knows postscript. Unfortunately, Word uses a third-party plugin to load EPS figures which produces a crappy low-res bitmap preview which is displayed on screen - when printed you get the high quality EPS though.
If the plots could be considered rasters (surface plots or image plots [heatmaps] with a high number of "pixels"), or if the plots contain a very large number of points, retaining the vector information for such plots will result in a large file size and high processing costs to load into Word and store in memory as you are working on the document. In such cases, I would use a high-res TIFF or a PNG via
png() respectively. See the help files for assistance in setting the size of the image in pixels and the resolution. These devices will render the figure as a bitmap image, which if given sufficient size/resolution will tolerate some amount of rescaling but will tend to be far more efficiently stored when the number of data points or cells is very large.
Do consider also that not all devices support transparency, largely because the underlying file formats do not allow it;
postscript() doesn't support transparency,
cairo_ps() does support transparency but in doing so will actually produce a bitmap image in EPS format, which might not be what you want.
Do note that if saving your document out to PDF, bitmap figures will be downsampled to some degree. I forget how Word controls this, but it had two settings in the Save dialog when PDF type was selected and one of those will downsample the images to produce a smaller file size. This will be associated with some loss of quality so be careful which option you choose. This is not specific to Word - OpenOffice.org and LibreOffice have the same features, but they offer far finer grained control of how the images are compressed and whether they are compressed or not. This arises because PDF was designed for both on screen and on printer reproduction. You don't need the high resolution in images if displaying on the screen for the web. Higher res images result in larger file sizes, so the intended destination of the PDF could be set, which affected how the PDF was created.
R graphics in windows can be pretty tricky. The biggest problem that I have is that anti-aliasing is not working properly in Windows. For some reason I need to use the Cairo device plugin to get it nicely formatted.
I've tried both Cairo and cairoDevice package and currently I find the cairoDevice to be the easiest and most reliable, there is a StackOverflow post about this.
To use the cairoDevice package all you need is to:
# Create the device Cairo_png(filename="my_file_name.png", width=16, height=16, pointsize=18) # Do a plot plot(x, y) # Saves the file dev.off()
You can also save in PDF/svg-format and then use Inkscape to edit your graph, change fonts etc and then export it to png format.
PDF, ps,SVG, or eps are vector based graphics device. JPG, TIFF,PNG,...etc are Raster graphics. When it comes raster graphics, the trade off is between the size and quality. By adjusting width,height and other formatting you could keep high quality in raster graphics. You could take PNG or JPG format to insert the image.
SVG images may insert in MSWORD document. You can check this.
The easiest way migth be chosing
.png files so did I. Yet word does show them quite blurred - at least in my case. Back when i was using Eviews i tried
.epswhich resulted in an own set of problems but the quality was better. I think in the end you have to chose between the lesser of two evils.
This does not directly answer your question, but you can get better integration between R and MS Word using either the R package R2wd or the commercial software Inference for R. These provide Sweave-like direct integration of R and MS Word, eliminating cut-and-paste or save-and-load, and making it easier to update plots in the document from the command line. I have not used these but I do use Sweave and recommend literate programming, which is supported by all of these tools.
Sweave is the most widely used literate programmiing tool among R users. It is LaTeX + R, and is how R vignettes and many books and journal articles are written.
The Word + R tools promise a less daunting interface for new users. LaTeX has a steeper learning curve than Word.
However, at $199/yr, inference for R makes it challenging for others to reproduce your analyses, unlike Sweave, which is part of base R.