How to use `officer` to set the border color of an object in powerpoint?

Viewed 127

I'd like to set the border color of a ggplot that I'm printing to a powerpoint using officer (not the plot.border element of the ggplot object, but the actual border line color of the object in Powerpoint).

I cannot figure out how to do it through the officer API!

For example, in this reproducible code, I'd like the plot object to have a "red" border - how do I do that? Thank you!

library(officer)
library(magrittr)
library(ggplot2)

p <- ggplot(data.frame(x = seq(10), y = rnorm(10)), aes(x, y)) + geom_col()

my_pres <- read_pptx() %>%
  add_slide() %>%
  ph_with(value = p, location = ph_location_type(type = "body"))

print(my_pres, "~/Desktop/new_example.pptx")
1 Answers

Is this what you are looking for?

library(officer)
library(magrittr)
library(ggplot2)

p <- ggplot(data.frame(x = seq(10), y = rnorm(10)), aes(x, y)) + geom_col() +
  theme(
    plot.margin = margin(0.5, 0.5, 0.5, 0.5, "cm"),
    plot.background = element_rect(
      colour = "red",
      size = 1
    )
  )
  

my_pres <- read_pptx() %>%
  add_slide() %>%
  ph_with(value = p, location = ph_location_type(type = "body"))

print(my_pres, "~/Desktop/new_example.pptx")

enter image description here

Related