Search code examples
rpowerpointlatticegrayscalereporters

configure ReporteRs to get grayscale lattice plots


is there a comforable way to get grayscale trellis plots with ReportRs? trellis.device(color=FALSE) seems not to work here

library(ReporteRs)
library(lattice)

trellis.device(color=FALSE) # set grayscale

p <- xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
            auto.key =list(space = "right"))

print(p) # ok, grayscale

doc = pptx("Test")
doc = addSlide(doc, "Title and Content")
doc = addPlot(doc, fun = print, x = p)  # not ok, colored
writeDoc(doc, "test.pptx")

here

enter image description here

instead of

enter image description here


Solution

  • it is OK when using trellis.par.set. See below:

    library(ReporteRs)
    library(lattice)
    
    p <- xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
                auto.key =list(space = "right"))
    
    ltheme <- standard.theme(color = FALSE) 
    
    doc = pptx("Test")
    doc = addSlide(doc, "Title and Content")
    doc = addPlot(doc, fun = {
      trellis.par.set(ltheme)
      print(p)
    }) 
    writeDoc(doc, "test.pptx")