user25494 user25494 - 1 month ago 18
R Question

How to set font type and name in ReporteRs::addPlot?

The code below creates a plot and embeds it into a Word document using the wonderful ReporteRs package. The code generates a warning:

"argument fontname is deprecated; please usefontname_serif, fontname_sans,fontname_mono,fontname_symbol instead"


I've been unable to figure out how to specify a specific font, e.g. "Times New Roman". Thanks!

library(ReporteRs)
library(magrittr)

x <- rnorm(100); y <- (1.5 * x) + rnorm(100, 0.1)

options( "ReporteRs-fontsize" = 12 )
doc <- docx() %>%
addPlot(function() plot(x,y, xlab = "Values of x", main="Test plot"), vector.graphic=TRUE, editable=TRUE, fontname="Times New Roman")
writeDoc( doc, file = "test.docx")

Answer

The solution, provided by the package author on the reporters-package google group:

https://groups.google.com/forum/#!topic/reporters-package/x3a_qWQ0hGc

   doc <- docx() %>%
      addPlot(function() plot(x,y, xlab = "Values of x", main="Test plot", family="serif"), vector.graphic=TRUE,
              editable=TRUE, fontname_serif = "Times New Roman")
    writeDoc( doc, file = "test.docx")