Producing a vector graphics image (i.e. metafile) in R suitable for printing in Word 2007

前端 未结 6 1293
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 23:04

First a caveat: I posted this question here on SuperUser, but it is clearly the wrong place to ask R questions. I recognize that it is not directly a programming question,

6条回答
  •  时光说笑
    2020-11-30 23:52

    The current best answer above to me is not acceptable, since if one goes to the trouble of making a nice vector based figure, the last thing one would like to do is just rasterize it to a bitmap... Unless it's an increadibly complex graph that takes ages to render in vector format, or something like that, but for most graphs that's not the case.

    The best solution is to export to Word directly in native Office vector format. I just made a new package, export, that allows one to do exactly that an allows export of either graphs or statistical tables to Word and Powerpoint, see https://cran.r-project.org/web/packages/export/index.html and for demo see https://github.com/tomwenseleers/export

    For example:

    install.packages("export")
    library(export)
    
    ?graph2ppt
    ?graph2doc
    ?table2ppt
    ?table2doc
    
    ## export of ggplot2 plot
    library(ggplot2)
    qplot(Sepal.Length, Petal.Length, data = iris, color = Species, 
          size = Petal.Width, alpha = I(0.7))
    # export to Word
    graph2doc(file="ggplot2_plot.docx", width=7, height=5) 
    # export to Powerpoint      
    graph2ppt(file="ggplot2_plot.pptx", width=7, height=5)
    

    enter image description here

    You can also export to enhanced metafile using the function

    graph2emf(file="ggplot2_plot.emf", width=7, height=5)
    

    but the quality of the native Office format is better.

    For final production you can also readily print it to PDF from Powerpoint if need be, and it will stay nicely in vector format then.

提交回复
热议问题