Search code examples
rpowerpointofficerrvg

What is the equivalent of officer::ph_location_fullsize( ) in the package rvg?


I would like to export multiple edible plots and tables from R to PowerPoint.

Below is a snippet of the code that I have, and the packages I'm using:

library(ggplot2)
library(dplyr)
library(tidyr)
library(gridExtra)
library(grid)
library(officer)
library(rvg)

read_pptx() %>%
   add_slide(layout = "Title and Content", master = "Office Theme") %>%
   ph_with_vg(code = grid.arrange(plot, table, col = 1), type = "body") %>%
   print(target = path)

In the output, the exported graph and table only covers the bottom 2/3 of the slide. How can I modify my code so that the content I'm trying to export could occupy the entire slide?

An additional question: If I would like to add a title to my slide, how do I specify the alignment (left preferred), size and color of the text? The default alignment is center, and I have not found a way to go around it.

Thank you.


Solution

  • Use ph_location_fullsize() and it will work.

    library(officer)
    library(magrittr)
    library(rvg)
    
    read_pptx() %>%
      add_slide(layout = "Title and Content", master = "Office Theme") %>%
      ph_with(value = dml(barplot(1:5)), location = ph_location_fullsize()) %>%
      print(target = "test.pptx")