davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
244 stars 44 forks source link

grid.newpage(): pptx device only supports one page #168

Closed abossenbroek closed 7 years ago

abossenbroek commented 7 years ago

I want to use the survminer package to draw beautiful survival plots. When I run the following code I receive an error message:

require(survival)
require(ReporteRs)
require(survminer)

fit <- survfit(Surv(time, status) ~ rx + adhere, data =colon)
plot <- ggsurvplot(fit, pval = TRUE,
                   break.time.by = 400,
                   risk.table = TRUE,
                   risk.table.col = "strata",
                   risk.table.height = 0.5, # Useful when you have multiple groups
                   palette = "Dark2")
require(ReporteRs)
doc = pptx(title = "Survival plots")
doc = addSlide(doc, slide.layout = "Title and Content")
doc = addTitle(doc, "First try")
doc = addPlot(doc, function() print(survplot))

The error message is:

 Error in grid.newpage() : pptx device only supports one page 

Traceback gives me:

11. grid.newpage() 
10. (function (..., newpage = TRUE) 
{
    if (newpage) 
        grid.newpage() ... 
9. do.call(gridExtra::grid.arrange, c(grobs, nrow = nplot, heights = heights)) 
8. print.ggsurvplot(survplot) 
7. print(survplot) 
6. fun(...) 
5. tryCatchList(expr, classes, parentenv, handlers) 
4. tryCatch(fun(...), finally = dev.off()) 
3. vector.pptx.graphic(doc = doc, fun = fun, pointsize = pointsize, 
    fontname_serif = fontname_serif, fontname_sans = fontname_sans, 
    fontname_mono = fontname_mono, fontname_symbol = fontname_symbol, 
    editable = editable, offx_, offy_, width_, height_, bg = bg,  ... 
2. addPlot.pptx(doc, function() print(survplot)) 
1. addPlot(doc, function() print(survplot)) 

SessionInfo:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gdtools_0.1.3        survminer_0.2.4      ggplot2_2.2.1        survival_2.39-5     
 [5] ReporteRs_0.8.8      ReporteRsjars_0.0.2  xlsx_0.5.7           xlsxjars_0.6.1      
 [9] rJava_0.9-8          data.table_1.9.6     RevoUtilsMath_10.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7        RColorBrewer_1.1-2 git2r_0.15.0       plyr_1.8.4        
 [5] R.methodsS3_1.7.1  R.utils_2.5.0      tools_3.3.2        digest_0.6.10     
 [9] memoise_1.0.0      tibble_1.2         gtable_0.2.0       lattice_0.20-34   
[13] png_0.1-7          Matrix_1.2-7.1     shiny_1.0.0        curl_2.2          
[17] gridExtra_2.2.1    withr_1.0.2        httr_1.2.1         xml2_1.1.0        
[21] knitr_1.15.1       RevoUtils_10.0.2   devtools_1.12.0    grid_3.3.2        
[25] R6_2.2.0           rvg_0.1.2          magrittr_1.5       scales_0.4.1      
[29] htmltools_0.3.5    splines_3.3.2      assertthat_0.1     mime_0.5          
[33] xtable_1.8-2       colorspace_1.3-2   httpuv_1.3.3       labeling_0.3      
[37] lazyeval_0.2.0     munsell_0.4.3      chron_2.3-47       R.oo_1.21.0  
davidgohel commented 7 years ago

When I print ggsurvplot, I get two plots, first is empty, second one is containing the plot... That's why. ReporteRs won't let you export 2 plots in one single placeholder.

David

slfan2013 commented 7 years ago

Hi, @davidgohel , how to fix this then?

davidgohel commented 7 years ago

@slfan2013 same than here but on the correct github page, I am not the author of survminer and I am sure he will be happy to solve that if this is not intentional.