I have seen that there is already a question about that known limitation for pptx. But is there a workaround like converting it first into an image and import that to pptx or something similar? I don‘t care that the table can‘t be edited afterwards, that would actually be an advantage.
Edit: Here as wished a minimal example where the Graphs are not included in the pptx.
library(flextable)
library(data.table)
library(officer)
library(dplyr)
z <- as.data.table(ggplot2::diamonds)
z <- z[, list(
price = mean(price, na.rm = TRUE),
list_col = list(.SD$x)
), by = "cut"]
z
ft <- flextable(data = z) %>%
compose(j = "list_col", value = as_paragraph(
plot_chunk(value = list_col, type = "dens", col = "pink",
width = 1.5, height = .4, free_scale = TRUE)
)) %>%
colformat_double(big.mark = " ", suffix = " $") %>%
set_header_labels(list_col = "density") %>%
autofit()
ft
print(ft, preview = "pptx")
You can use the new grid output feature for that—the following code demo some of its features (see ?gen_grob
for more informations):
library(flextable)
library(data.table)
library(officer)
library(dplyr)
z <- as.data.table(ggplot2::diamonds)
z <- z[, list(
price = mean(price, na.rm = TRUE),
list_col = list(.SD$x)
), by = "cut"]
z
ft <- flextable(data = z) %>%
mk_par(j = "list_col", value = as_paragraph(
plot_chunk(value = list_col, type = "dens", col = "pink",
width = 1.5, height = .4, free_scale = TRUE)
)) %>%
colformat_double(big.mark = " ", suffix = " $") %>%
set_header_labels(list_col = "density") %>%
autofit()
ft
# create powerpoint
ppt <- read_pptx() %>%
add_slide() %>%
ph_with(value = plot_instr(code = plot(ft, fit = FALSE, scaling = "fixed")),
location = ph_location_type()) %>%
add_slide() %>%
ph_with(value = plot_instr(code = plot(ft)),
location = ph_location_fullsize()) %>%
add_slide() %>%
ph_with(value = plot_instr(code = plot(ft, fit = "width", scaling = "min")),
location = ph_location_fullsize())
# save powerpoint
print(ppt, preview = "pptx", target = 'output.pptx')