我想知道是否可以将flextable/regulartable、ggplot、文本和图像组合成一个网格对象,然后将该网格放在PowerPoint幻灯片中?这对于在幻灯片中排列对象而不必计算每个对象的坐标非常有用。我看到了通过grid.arrange组合和排列ggplot对象的示例(r-为什么我不能使用OfficeR将一组图形放在网格中发送到PowerPoint?)但如果我想添加一个flextable或者可能是一个新的文本段落,它就无法工作了。是否有一种使用网格布局改善演示层的方法?谢谢!
自从flextable 0.5.3
版本以来,这是有可能的。有很多方法可以实现,以下是一个示例:
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) )
以下是结果:
magick
的包,而我无法使用它。还有其他方法吗?我正在使用 flextable 版本 0.5.9。 - PeterD