Export and import R eps in Word 2010

I am having problems exporting eps files from R and importing into Word 2010.

I use ggplot2 graphics like

 library(ggplot2) p <- qplot(disp,hp,data=mtcars) + stat_smooth() p 

Even after calling setEPS() none of the following product files that can be successfully imported.

 ggsave("plot.eps") postscript("plot.eps") print(p) dev.off() 

It is strange that if I create a graph using FileSave AsPostscript in the menu in the graphical interface, it can be imported correctly. However, when a Word document is subsequently exported as pdf, the fonts on the chart are slightly jagged.

So my questions are:

  • What combination of settings ( ggsave / Postscript ) allows me to create eps files that can be imported into Word 2010?
  • How can I guarantee that fonts remain clear when a Word document is exported in pdf format?

Update

After more research, I was able to get more luck with cairo_ps for creating graphs. However, when importing into Word, the text does not appear.

In addition, after checking the various eps outputs ( cairo_ps , saving from the graphical user interface, ggsave ) in the latex document, it seems that the eps import filter in Word is pretty bad, since the print / match the quality of the latex document. The ggsave version (which uses Postscript ) had some color issues that the other two methods did not have.

The conclusion is that this is a Word problem and therefore fortune(109) does not apply. I would be happy if it were proved differently, but I will give an answer and an award to those who can provide teams that can replicate the output from the GUI in the form of a command.

+6
source share
5 answers

This worked for me ... following the tips on the postscript help page:

  postscript("RPlot.eps", height = 4, width = 4, horizontal = FALSE, onefile = FALSE, paper = "special") library(ggplot2) p <- qplot(disp,hp,data=mtcars) + stat_smooth() p #geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to #change the smoothing method. #Warning message: #In grid.Call.graphics(L_polygon, x$x, x$y, index) : # semi-transparency is not supported on this device: reported only once per page dev.off() #quartz # 2 

The funny stuff at the end tells you that this is just a Mac-tested solution, anyway.

Edit: I just tested it with R version 2.15.1 (2012-06-22) - "Fried Marshmallows": platform: i386-pc-mingw32 / i386 (32-bit version) and MS Word 2007 in Win XP and this It worked. The commands were Insert / Picture ... / select eps format / select file.

Edit2: There is another way to save than using the postscript device directly. The savePlot method with "eps" mode is available on Windows (but not Mac). I agree that the fonts are not as smooth as on a Mac, but I see no difference in quality between saving with savePlot and using saving from an interactive window.

 savePlot(filename = "Rplot2", type = "eps", device = dev.cur(), restoreConsole = TRUE) 

savePlot calls (.External(CsavePlot, device, filename, type, restoreConsole))

+4
source

I solved the problem with exporting .eps files from R and importing into Word 2010 in Windows 7 using the colormodel="rgb" (default "srgb" ) "srgb" of the postscript command.

 postscript("RPlot.eps", height = 4, width = 4, horizontal = FALSE, paper = "special", colormodel = "rgb") library(ggplot2) p <- qplot(disp,hp,data=mtcars) + stat_smooth(se=FALSE, method="loess") p dev.off() 
+4
source

You are probably better off using wmf as the format you can create on Windows.

+1
source

The word really does not support EPS very well. the best solution I've seen so far to make R-graphics (basic R graphics, trellis graphics or ggplots) work together with Office (Word, Powerpoint) is to export them directly to Powerpoint using ReporteRs , as in

 library( ReporteRs ) require( ggplot2 ) mydoc = pptx( ) mydoc = addSlide( mydoc, slide.layout = "Title and Content" ) mydoc = addTitle( mydoc, "Plot examples" ) myplot = qplot(Sepal.Length, Petal.Length , data = iris, color = Species , size = Petal.Width, alpha = I(0.7) ) mydoc = addPlot( mydoc, function( ) print( myplot ), vector.graphic=TRUE) writeDoc( mydoc, file = "test plot.pptx" ) 

enter image description here

This leads to fully editable high-quality Powerpoint graphics in Office-native drawingML, which you can also easily copy and paste as an extended metafile if you like (using Copy ... Paste special ... Enhanced metafile), and which unlike EMFs exported from R, they also fully support transparency. For final processing, you can also easily print it in Powerpoint PDF format, if necessary, and it will be well saved in vector format, and then in good quality.

For the base diagram R, the syntax will look like this:

 library( ReporteRs ) mydoc = pptx( ) mydoc = addSlide( mydoc, slide.layout = "Title and Content" ) mydoc = addTitle( mydoc, "" ) myplot = function( ) {return(plot(c(1:100), c(1:100), pch=20))} mydoc = addPlot( mydoc, fun=myplot, vector.graphic=TRUE, offx=0,offy=0,width=12, height=8, fontname="Calibri", pointsize=20) writeDoc( mydoc, file = "test plot2.pptx" ) 
+1
source

You can use R studio to attach html files with all your plots, and then open HTML files using Word.

textbook

0
source

Source: https://habr.com/ru/post/927031/


All Articles