group a flextable, a ggplot, a text and an image together into a grid object, then add it to a powerpoint slide
Asked Answered
O

1

5

I want to know if it's possible to group a flextable/regulartable, a ggplot, a text and an image together into a grid object, and then put that grid in a PowerPoint slide?

This could be very useful for arranging the objects inside a power point slide without being forced to calculate always the coordinates of every object.

I saw an example with combining and arranging ggplot objects through grid.arrange (r - Why can't I send a group of plots in a grid to PowerPoint with OfficeR?) But if I want to add also a flextable or maybe a new text paragraph, it doesn't work anymore.

Is there a way to improve the presentation layer whit a grid layout?

Thank you!

Onieonion answered 19/7, 2018 at 10:3 Comment(0)
P
7

It is possible since version 0.5.3 of flextable. There are many ways to achieve that, here is one example:

library(ggplot2)
library(grid)
library(cowplot)
library(dplyr)
# remotes::install_github("davidgohel/flextable")
library(flextable)

gg1 <- ggplot(iris, aes(Sepal.Length, Petal.Length, color = Species) ) + geom_point()

ft_raster <- iris %>% group_by(Species) %>% 
  summarise_all(median) %>% 
  flextable() %>% autofit() %>% 
  as_raster()

gg2 <- ggplot() + 
  theme_void() + 
  annotation_custom(rasterGrob(ft_raster), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)

cowplot::plot_grid(gg1, gg2, nrow = 2, ncol = 1, rel_heights = c(3, 1) )

And the result below

enter image description here

Psilomelane answered 6/5, 2019 at 17:13 Comment(1)
Unfortunately this answer is not fully reproducible because it needs another package named magick which I am not able to use. Is there another way? I'm using flextable version 0.5.9.Resonant

© 2022 - 2024 — McMap. All rights reserved.