1

When using officer and the rvg graphics I want my images to not have the background white square. The reason for this is that some functions leave a lot of empty space up at the top and often this will overlap with the header. I can go in and delete each one but when making 20 or more plots this gets tedious fast.

Specifically I want to use this with the forest function in metafor used here in the example.

Before deleting the background.

enter image description here

**

After deleting the background.

** enter image description here

library(officer)
doc <- read_pptx()
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <- ph_with_vg_at(doc, code = barplot(1:5, col = 2:6),
                     left = 1, top = 2, width = 6, height = 4)


library(metafor)
library(gemtc)
network <-mtc.network(smoking$data.ab)
data(dat.bcg)
plot(network)
res <- rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure="RR",
           slab=paste(author, year, sep=", "), method="REML")
forest(res)
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <-  ph_with_vg(doc, code = plot(network), type = "body", width = 8, height = 6)
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <-  ph_with_vg(doc, code = forest(res), type = "body", width = 8, height = 6)

print(doc, target = "vg.pptx")
  • you need to set a transparent background for your plot (sorry can not reproduce your example as I am not able to install gemtc) – David Gohel Aug 09 '18 at 08:26
  • I do not know the `officer` package, but running `par(bg=NA)` before the call to `forest()` should make the background transparent. – Wolfgang Aug 10 '18 at 09:00

1 Answers1

1

This is now possible using the latest rvg update and setting the background to "NA".

anyplot = dml(code = barplot(1:5, col = 2:6), bg = "NA")

    doc <- read_pptx()
    doc <- add_slide(doc)
    doc <- ph_with(doc, anyplot, location = ph_location_fullsize())

    print(doc, target = "bg.pptx")