4

When I knit a document containing multiple plots obtained through purrr:map function, I get text slides in between each plot slide containing unwanted list index information (see image slides 2, 4, and 6). I'd like to remove these and just have plots.

  • I've tried results = "hide" and results = FALSE in the header. These just return one plot instead of many, AND the text is still there.
  • I've tried adding invisible() around my code as recommended here. I don't see a difference.

How can I remove these and just have three slides with the three plots with no text?

powerpoint tray showing alternating plot and text slides

---
title: "Reprex"
output: powerpoint_presentation
---

```{r include=FALSE}
library(tidyverse)
```

```{r echo=FALSE, results = FALSE}
ys <- c("mpg","cyl","disp")
ys %>% map(function(y) 
    invisible(ggplot(mtcars, aes(hp)) + geom_point(aes_string(y=y))))
```
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
datakritter
  • 590
  • 5
  • 19

1 Answers1

5

Try this:

  1. To suppress the console output use purrr::walk instead of map. See e.g. https://chrisbeeley.net/?p=1198
  2. To get each plot printed on a separate slide use results='asis' and add two newlines via cat('\n\n') after each plot.

    ---
    title: "Reprex"
    output: powerpoint_presentation
    ---
    
    ```{r include=FALSE}
    library(tidyverse)
    ```
    
    ```{r echo=FALSE, results='asis'}
    ys <- c("mpg","cyl","disp")
    walk(ys, function(y) {
      p <- ggplot(mtcars, aes(hp)) + geom_point(aes_string(y=y))
      print(p)
      cat('\n\n')
    })
    ```

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51