So I need to copy and paste plots I make in R/Rstudio to PowerPoint (Unfortunately my government client requires everything to be in PowerPoint, otherwise this question could easily be solved by just putting my graphics in an Rmarkdown file). This hasn't been that much of an issue until recently where I discovered that transparent objects can't be copy and pasted to PowerPoint, at least in the method I've been using (Export > Copy as Metafile > Copy Plot > Paste). Instead, where the transparent objects were, there's now nothing. I have done some reading and found that this has to do with my "graphics engine" not supporting transparent objects and that a "cairo" engine can but I don't understand what that means or if it's an option I can change in Rstudio or PowerPoint.
Here's some example code:
iris %>%
mutate(small_petal = if_else(Petal.Width > 1.5, "big", "small")) %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species, alpha = small_petal)) +
geom_point()
I've tried a pretty extravagant workaround to get the colors I want. I've made custom RGB values which are non-transparent to mimic the transparency I want. I then attach them to the data.frame using mutate
with four if_else
s (one color for each alpha-color combination). I then use scale_fill_identity
to apply my custom colors but it then produces a legend with elements I don't want. I need to use the following to make a legend appear with at least some of the elements I want:
scale_fill_identity(guide = "legend",
labels = c("DUMMY LABEL",
"DUMMY LABEL",
"Small Petal",
"Big Petal"),
breaks = unique(iris$custom_colors))
I then delete the legend objects I don't want in PowerPoint. Any help is greatly appreciated.