When using officer and rvg, can you remove or prevent the background white square behind the image inserted into PowerPoint from the code?

422 views Asked by At

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")
1

There are 1 answers

0
Lionel Duarte On

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")