R eps export and import into Word 2010

后端 未结 5 459
别跟我提以往
别跟我提以往 2020-12-18 06:29

I\'m having trouble with exporting eps files from R and importing into Word 2010.

I\'m using ggplot2 plots, eg

library(ggplot2)
p <-          


        
相关标签:
5条回答
  • 2020-12-18 06:42

    I solved the problem with exporting .eps files from R and importing into Word 2010 on Windows 7 using the colormodel="rgb" option (defaults to "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()
    
    0 讨论(0)
  • 2020-12-18 06:44

    Word indeed doesn't support EPS very well. A better solution is to export your graphs to Word or Powerpoint directly in native Office format. I just made a new package, export, that does exactly that, see https://cran.r-project.org/web/packages/export/index.html and for demo https://github.com/tomwenseleers/export

    Typical syntax is very easy, e.g.:

    install.packages("export")
    library(export)
    library(ggplot2)
    qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
          size = Petal.Width, alpha = I(0.7))     
    graph2doc(file="ggplot2_plot.docx", width=6, height=5)
    graph2ppt(file="ggplot2_plot.pptx", width=6, height=5) 
    

    Output is vector format and so fully editable after you ungroup your graph in Word or Powerpoint. You can also use it to export statistical output of various R stats objects.

    0 讨论(0)
  • You can use R studio to knit html files with all of your plots and then open HTML files with Word.

    knitr tutorial

    0 讨论(0)
  • 2020-12-18 06:54

    This worked for me... following advice in 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 puts you on notice that this is only a Mac-tested solution, so far anyway.

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

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

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

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

    0 讨论(0)
  • 2020-12-18 06:56

    You are probably better of using wmf as a format which you can create on Windows.

    0 讨论(0)
提交回复
热议问题