Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when plotting survminer output with ReporteR #110

Closed
abossenbroek opened this issue Jan 16, 2017 · 7 comments
Closed

Error when plotting survminer output with ReporteR #110

abossenbroek opened this issue Jan 16, 2017 · 7 comments

Comments

@abossenbroek
Copy link

@abossenbroek abossenbroek commented Jan 16, 2017

I want to use the survminer package to draw beautiful survival plots in a PPTX. 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  
@zzawadz
Copy link
Contributor

@zzawadz zzawadz commented Jan 16, 2017

I've added quick fix for that on my fork. Please try:

devtools::install_github("zzawadz/survminer")
require(survival)
require(ReporteRs)
#install.packages("survminer")
require(survminer)

fit <- survfit(Surv(time, status) ~ rx + adhere, data =colon)
survplot <- 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), vector.graphic = TRUE)
writeDoc(doc, "test.pptx")
@kassambara
Copy link
Owner

@kassambara kassambara commented Jan 16, 2017

Great! I'll take this modification into account!

@zzawadz
Copy link
Contributor

@zzawadz zzawadz commented Jan 16, 2017

This is just quick fix:)

I'll make sure if everything is ok, and them I'll create pull request:)

@kassambara
Copy link
Owner

@kassambara kassambara commented Jan 16, 2017

Thank you in advance for your contribution!!

@zzawadz
Copy link
Contributor

@zzawadz zzawadz commented Jan 16, 2017

Unfortunately my quick fix doesn't solve the issue.

Adding newpage = FALSE causes that new plot is created on top of previous:( So it spoils normal behaviour in interactive session.

I think that wy may need to add new parameter in print.ggsurvplot with default value TRUE, with note that for ReporteR it should be set to FALSE. I'll think about it.

@kassambara
Copy link
Owner

@kassambara kassambara commented Jan 21, 2017

Issue fixed with this sweet pull request: #111
Thanks @zzawadz

@kassambara kassambara reopened this Jan 21, 2017
kassambara added a commit that referenced this issue Jan 21, 2017
@kassambara kassambara closed this Jan 21, 2017
@kassambara
Copy link
Owner

@kassambara kassambara commented Feb 15, 2017

Now the function gridExtra::arrangeGrob()is used to arrange ggsurvplots instead of the function grid.arrange().

So no longer need to use the argument newpage = FALSE, for ReporteR.

@kassambara kassambara reopened this Feb 15, 2017
kassambara added a commit that referenced this issue Feb 15, 2017
kassambara added a commit that referenced this issue Feb 15, 2017
@kassambara kassambara closed this Feb 15, 2017
kassambara added a commit that referenced this issue Feb 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.