I'm using the officer
package to write ggplots to Powerpoint, and even though my plots look good in my Rstudio viewer, my plots are getting "squished" when I add them to any custom slide with smaller content boxes.
I did my best to reproduce my issue with the following code:
library(tidyverse)
library(officer)
p <- data.frame(x = rnorm(100)) %>%
ggplot() +
geom_density(aes(x)) +
labs(title = "This is a title") +
annotate("text", x = 0, y = 0.2, label = "This is some text")
read_pptx("~/Downloads/template.pptx") %>%
add_slide(layout = "Title and Content") %>%
ph_with(p, location = ph_location_type("body", id = 1)) %>%
add_slide(layout = "text_example") %>%
ph_with(p, location = ph_location_type("body", id = 1)) %>%
print("~/Desktop/test_example.pptx")
Where template.pptx
is a copy of the officer template with the "Title and Content" slide duplicated (and named "test_example") and content box shrunken down a little bit (available here for reproducibility).
The first slide looks good, like this:, but the second slide has the dimensions of the plot shrunken while the content in the plot stays the same size, giving it a "squished" feel:
Has anyone run into this before? Are there any tricks/hacks out there that can tell my plot to decrease the size of all it's elements when the total image space is decreased? I'd like to maintain the relative size of the elements of the plot as I move to different slide templates.
If you're still here - THANK YOU FOR READING SO FAR! I'd appreciate any and all tips :)