Export plot with high quality from R to Word

user4482513 picture user4482513 · Jan 22, 2015 · Viewed 16.4k times · Source

I did a plot in R & I want to define some format issues in my plot but I haven't got it.

  1. Is it possible define the size of plot? How?
  2. I want change the font family for Times New Roman. Is it possible?
  3. How do it export a plot to Word with high quality. I tried with tiff but the plot wasn't good.

Answer

David Gohel picture David Gohel · Jan 22, 2015

You can use ReporteRs package to export the plot to Word. See the following example - it will produce a .docx file containing an editable graph in a vector graphics format (high quality) with a defined size.

library( ggplot2 )
library( ReporteRs )
doc = docx( )

myplot = qplot(Sepal.Length, Petal.Length, data = iris
  , color = Species, size = Petal.Width, alpha = I(0.7) )

doc = addPlot( doc = doc, fun = print, x = myplot, 
  vector.graphic = T, # vector graphic instruction
  fontname = "Times New Roman",  # font specification
  width = 4, height = 4 #dim. are in inches
  )

writeDoc( doc, file = "test.docx" )