## Slide with Plot
library(patchwork)
library(tidyverse)
# prep frequency table
freqtable <- table(mpg$manufacturer)
df <- as.data.frame.table(freqtable)
head(df)
theme_set(theme_classic())
# Plot
g <- ggplot(df, aes(Var1, Freq))
g <- g + geom_bar(stat="identity", width = 0.5, fill="tomato2") +
theme(axis.text.x = element_text(angle=65, vjust=0.6)) +
theme(axis.title.x = element_blank())
g+g+g+g
This produces 2 slides. I have 2 questions:
How do I prevent the first slide from being produced so that only the plot slide is created?
How do I change the dimensions/size of the plot? I am using Patchwork to create a 4x4 plot which I want to save to a PowerPoint slide. The code above successfully creates the 4x4 plots but when I execute the above Markdown program, the plot is too small on the powerpoint slide. I have tried the fig.width and fig.height options and a few other suggested methods but none of them appear to affect the size of the plot in PowerPoint. I am also not clear on how to create a custom template - it is difficult for me to understand the directions for doing so....
You're getting close! They key thing here is creating a template PPT that has a slide area that takes up the whole slide. While you're using a custom template, you can also get rid of the title slide and no extra slide will render.
See here for an example template that I use in the code below to generate what I believe you are looking for.
The easiest thing to do would be to download template-no-title.pptx and put it in the same directory as your Rmd file that you will be knitting. Then, the Rmd file will look something like this:
Sweet! Thanks Matt! I'll look at it right away - I figured it would require a custom template but I wasn't understanding where to find it or save it, so you answered that question. (Ironically, I downloaded your template last night but couldn't figure out where it was supposed to go.)
Thanks again!
Great! Seems like you're pretty close to what you want. I did have to fiddle around a bit with my PPT template and the fig.width and fig.height chunk options to get my plots to fill up the slide how I wanted.
In the PPT template (which is just a blank PPT file), you can go in to the Slide Master View and change the size and spacing of the slide elements. This is where you could also add a logo or other PPT theme so that when you render from Rmd using that template file, it uses those slide layouts you have defined.
Getting a message saying "The Picture Can't be Displayed" in PowerPoint after Knitting the below code. I did save the template-no-title.pptx to the directory where the Rmd file is saved.
You might try change the dev argument to "png" or something else. This controls which graphics device is used for image rendering. I liked the way the "svg" looked on my machine, but that could be problem for you. See here https://yihui.org/knitr/options/#plots for more info on knitr graphics devices.