#' Puts a graph into a PowerPoint slide.
#'
#' @description A function that creates a slide for displaying a ggplot graph.
#'
#' @param presentation_template Powerpoint template.
#' @param slide_ID The name of the slide for QA.
#' @param myplot The graph you want to display in the slide.
#' @param description_text text string to add below plot. empty by default.
#' @param title Set a title at the top of the slide.
#' @param layout The name of the layout in the template. The default is 'content_slide'.
#' @param master The name of the slide template. The default is 'master_content'.
#'
#' @return Produces a single slide in the presentation.
#'
#' @examples
#' new_presentation <- ppt_template %>%
#' add_slide_plot(slide_id = "a printted QA name",
#' myplot = ggplot(mtcars, aes(mpg, disp)) + geom_point(),
#' title = "A very simple plot in a simple slide")
#' print(new_presentation, "tmp.pptx")
#'
#' @export
add_slide_plot <- function(presentation_template, slide_id = "", myplot,
description_text = "", title = "?",
layout = "content_slide", master = "master_content"){
if (slide_id != "") {
cat("in ", slide_id, " \n")
}
if (description_text != "") {
presentation_template <- presentation_template %>%
officer::add_slide(layout = layout, master = master) %>%
officer::ph_with(value = title, location = officer::ph_location_label("title")) %>%
officer::ph_with(value = myplot, location = officer::ph_location_label("content")) %>%
officer::ph_with(value = description_text, location = officer::ph_location_label("desc"))
} else {
presentation_template <- presentation_template %>%
officer::add_slide(layout = layout, master = master) %>%
officer::ph_with(value = title, location = officer::ph_location_label("title")) %>%
officer::ph_with(value = myplot, location = officer::ph_location_label("content"))
}
return(presentation_template)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.