2

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")
redarah
  • 152
  • 7

1 Answers1

1

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

TarJae
  • 72,363
  • 6
  • 19
  • 66
  • 1
    Thank you but no. I'm trying to change the outline color of the shape itself (in powerpoint) - which is important because I'll need folks to be able to edit it later (which you can't edit the ggplot color after the fact) – redarah May 20 '21 at 21:20
  • @redarah Have you looked into the `rvg` package, which creates R graphs that PowerPoint users can modify, or the `mschart` package, which allows you to use R to create native PowerPoint charts? – coip Apr 20 '22 at 22:04