0

I want to save different objects on a powerpoint slide and generate a deck using RMarkdown.

I found Side-by-side plots with ggplot2 to display two ggplot, but it did not work for plotly images.

My use case would like to combine

  • up to 3 flextables

  • plotly image

  • text box with specific location

our current solution is to save each as images and write them to a ppt, but this is not optimal.

My sample rmd is here:

---
title: "Untitled"
output: powerpoint_presentation
date: "2023-01-13"
---


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

## Slide with R Output

```{r echo = FALSE}
df = data.frame(col1="brocolli", col2 = "and spinach and kale and peas and lettuce")
df %>%
  flextable() %>%
  fontsize(part = "all", size = 7) %>%
  width(2,5)
```

## 
```{r echo = FALSE}
df = data.frame(col1="Apples", col2 = "and bananas and oranges and pears and pinapple")
df %>%
  flextable() %>%
  fontsize(part = "all", size = 7) %>%
  width(2,5)
```

## Slide with Plot

```{r pressure}

trace_0 <- rnorm(100, mean = 5)
trace_1 <- rnorm(100, mean = 0)
trace_2 <- rnorm(100, mean = -5)
x <- c(1:100)

data <- data.frame(x, trace_0, trace_1, trace_2)

fig <- plot_ly(data, x = ~x, y = ~trace_0, name = 'trace 0', type = 'scatter', mode = 'lines') 
fig <- fig %>% add_trace(y = ~trace_1, name = 'trace 1', mode = 'lines+markers') 
fig <- fig %>% add_trace(y = ~trace_2, name = 'trace 2', mode = 'markers')

fig
```

```{r}

df = data.frame(matrix(round(rnorm(150),2), ncol = 10))
df %>%
  flextable() %>%
  fontsize(part = "all", size = 7)
```

result after I save each table/plot as png and save into single ppt slide is here (ignore the text in red, just for clarity where each chunk placed and where textbox would be added)

enter image description here

Are there any suggestions on if it is possible to include all the objects on a single slide?

frank
  • 3,036
  • 7
  • 33
  • 65

0 Answers0