pharmaverse / ggsurvfit

http://www.danieldsjoberg.com/ggsurvfit/
Other
67 stars 19 forks source link

exporting to pptx #133

Closed asreiner closed 1 year ago

asreiner commented 1 year ago

I'm trying to implement the following: https://www.pipinghotdata.com/posts/2020-09-22-exporting-editable-ggplot-graphics-to-powerpoint-with-officer-and-purrr/

Using the code below, but I'm getting the error: 'Error in grid.newpage() : pptx device only supports one page'

Any help appreciated. Thanks!

library(palmerpenguins) library(dplyr) library(survival) library(ggsurvfit) library(here) library(glue) library(officer) library(rvg) library(viridis)

penguins<-penguins%>% mutate(dead = ifelse(sex == 'female', 0, ifelse(sex == 'male', 1, 2)), fupm = bill_depth_mm )

os<-survfit2(Surv(fupm,dead)~1, data=penguins)%>% ggsurvfit(size=1)+ add_risktable() os

os_dml <- rvg::dml(ggobj = os)

officer::read_pptx() %>% officer::add_slide() %>% officer::ph_with(os_dml, ph_location(width=8, height=10)) %>% base::print( target = here::here( "Figure1.pptx" ) )

shannonpileggi commented 1 year ago

Looks related to this issue: https://github.com/davidgohel/ReporteRs/issues/168 and this post on SO: https://stackoverflow.com/questions/48407569/r-why-cant-i-send-a-group-of-plots-in-a-grid-to-powerpoint-with-officer but I haven't gotten to the solution yet - I'm not too familiar w/ methods & classes for ggplot.

ddsjoberg commented 1 year ago

@asreiner ggsurvfit uses patchwork in the background to combine the primary plot with the risktables. From the SO post @shannonpileggi linked to, it seems that grid.arrange() may work in this context.....but i tried it and it didn't work!

Looks like it's not supported unfortunately