R Markdown Presentation: showing one plot in each slide

Viewed 41

I have a list of 300 plots and want one PowerPoint slide to show one plot (300 slides). What's the best way to achieve this?

A toy example using the built-in iris dataset to create a list of plots:

purrr::map(names(iris[,-5]), function(col_name){
  plot = iris %>% 
    ggplot(aes(x = !!as.name(col_name))) + 
    geom_histogram()
  return(plot)
})

I hope to create PowerPoint slides with one plot on each slide.

1 Answers

I will be using the iris data set, which is a built-in data set often used to populate example code.

With the following code in a Rmd file:

---
title: "Test_PowerPoint"
author: "KoenV"
date: '2022-06-30'
output: powerpoint_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r include=FALSE, warning=FALSE, message=FALSE}
library(tidyverse)
library(purrr)
```

```{r, iris, fig.cap="A scatterplot.", echo=FALSE, warning=FALSE, message=FALSE}

## your code    
purrr::map(names(iris[,-5]), function(col_name){
  plot = iris %>% 
    ggplot(aes(x = !!as.name(col_name))) + 
    geom_histogram()
  return(plot)
})

```

And after hitting the "knit" button, you will see a PowerPoint presentation appearing, with the following lay-out:

enter image description here

Please let me know, whether this is what you wanted.

Related