2

Please consider the following:

With the survminer package we can draw 'log-log' plot for survival objects created with the package survival. This has been introduced a while ago by the package developer @kassambara here.

Until recently everything worked fine but with an update to a newer R and RStudio version I receive a warning message and an empty plot.

require("survival")
#> Loading required package: survival
require("survminer")
#> Loading required package: survminer
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data = lung, fun = "cloglog")
#> Warning: Transformation introduced infinite values in continuous x-axis

#> Warning: Transformation introduced infinite values in continuous x-axis

print(sessionInfo(), locale = FALSE)
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 16299)
#> 
#> Matrix products: default
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] survminer_0.4.6   ggpubr_0.2.3      magrittr_1.5      ggplot2_3.2.1    
#> [5] survival_2.44-1.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.1        pillar_1.4.2      compiler_3.6.1   
#>  [4] highr_0.8         tools_3.6.1       digest_0.6.20    
#>  [7] nlme_3.1-140      evaluate_0.14     tibble_2.1.3     
#> [10] gtable_0.3.0      lattice_0.20-38   pkgconfig_2.0.2  
#> [13] rlang_0.4.0       Matrix_1.2-17     yaml_2.2.0       
#> [16] xfun_0.8          gridExtra_2.3     withr_2.1.2      
#> [19] stringr_1.4.0     dplyr_0.8.3       knitr_1.23       
#> [22] survMisc_0.5.5    generics_0.0.2    grid_3.6.1       
#> [25] tidyselect_0.2.5  data.table_1.12.2 glue_1.3.1       
#> [28] KMsurv_0.1-5      R6_2.4.0          km.ci_0.5-2      
#> [31] rmarkdown_1.15    tidyr_0.8.3       purrr_0.3.2      
#> [34] backports_1.1.4   scales_1.0.0      htmltools_0.3.6  
#> [37] splines_3.6.1     assertthat_0.2.1  xtable_1.8-4     
#> [40] colorspace_1.4-1  ggsignif_0.6.0    labeling_0.3     
#> [43] stringi_1.4.3     lazyeval_0.2.2    munsell_0.5.0    
#> [46] broom_0.5.2       crayon_1.3.4      zoo_1.8-6

Created on 2019-09-04 by the reprex package (v0.3.0)

My RStudio version is 1.2.1335


I flagged this with the package developer here but he does not seem to be able to reproduce the same error (see here).

For me the error occurs at both Windows and Mac. In the meantime, I updated all packages on both systems with update.packages(checkBuilt = TRUE, ask = FALSE) but without any success. Strangely enough, a colleague of mine working with an older version of R and RStudio can draw the plot just fine, just as the package developer.

What am I doing wrong and what can I do?

Thanks!


Update
Rolling back several versions of R and packages, I found one combination of versions (R and packages) that do work. I don't fully understand how this can be but it seems that there is an interaction of one or more packages with an R version that is not working well. I attach the session info of the working combination here and leave it to the masterminds to explore further (if there is any interest).

require("survival")
#> Loading required package: survival
require("survminer")
#> Loading required package: survminer
#> Warning: package 'survminer' was built under R version 3.5.3
#> Loading required package: ggplot2
#> Warning: package 'ggplot2' was built under R version 3.5.3
#> Loading required package: ggpubr
#> Warning: package 'ggpubr' was built under R version 3.5.3
#> Loading required package: magrittr
fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data = lung, fun = "cloglog")

print(sessionInfo(), locale = FALSE)
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS  10.14.6
#> 
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] survminer_0.4.2 ggpubr_0.2.3    magrittr_1.5    ggplot2_3.1.1  
#> [5] survival_2.42-3
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.2        compiler_3.5.1    pillar_1.4.2     
#>  [4] plyr_1.8.4        highr_0.8         tools_3.5.1      
#>  [7] digest_0.6.20     nlme_3.1-137      evaluate_0.14    
#> [10] tibble_2.1.3      gtable_0.3.0      lattice_0.20-35  
#> [13] pkgconfig_2.0.2   rlang_0.4.0       Matrix_1.2-14    
#> [16] cmprsk_2.2-7.1    yaml_2.2.0        xfun_0.9         
#> [19] gridExtra_2.3     withr_2.1.2       stringr_1.4.0    
#> [22] dplyr_0.8.3       knitr_1.24        survMisc_0.5.5   
#> [25] generics_0.0.2    grid_3.5.1        tidyselect_0.2.5 
#> [28] data.table_1.12.2 glue_1.3.1        KMsurv_0.1-5     
#> [31] R6_2.4.0          km.ci_0.5-2       rmarkdown_1.15   
#> [34] tidyr_0.8.3       purrr_0.3.2       backports_1.1.4  
#> [37] scales_1.0.0      htmltools_0.3.6   splines_3.5.1    
#> [40] assertthat_0.2.1  xtable_1.8-4      colorspace_1.4-1 
#> [43] ggsignif_0.6.0    labeling_0.3      stringi_1.4.3    
#> [46] lazyeval_0.2.2    munsell_0.5.0     broom_0.5.2      
#> [49] crayon_1.3.4      zoo_1.8-6

Created on 2019-09-05 by the reprex package (v0.3.0)


Possible work-around
The answer by @Robbe is a possible work-around! I am hesitant to mark this as the correct answer though. Any advice on this would be welcome too.

Frederick
  • 810
  • 8
  • 28
  • Just spitballing ideas, can you try opening the image in a web browser instead of the RStudio Viewer pane. Still blank? – JasonAizkalns Sep 04 '19 at 16:19
  • Yes. It’s still blank. I actually noticed this problem while rendering a “gitbook” (HTML) through the bookdown package. PDF documents also return the same blank plot. IMHO this must have something to do with the warning message “Transformation introduced [...]” and this should be independent of the rendered plot. Can you replicate the error message or do you receive a plot? – Frederick Sep 04 '19 at 16:50

2 Answers2

2

I got the same error as you, but you can make it work by ommitting 0 in the x-axis by setting xlim:

fit <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data = lung, fun = "cloglog", xlim = c(1, 1000))

This is because the x-axis is log-transformed and log(0) is minus infinity, which causes the error.

ggsurvplot doesnt seem to do this automaticaly whereas plot for example does:

fit<- survfit(Surv(time, status) ~ sex, data = lung)
plot(fit, data = lung, fun = "cloglog")

with warning message:

1: In xy.coords(x, y, xlabel, ylabel, log) :
  1 x value <= 0 omitted from logarithmic plot
Robbe Caes
  • 121
  • 6
  • Thanks for this! I updated my question because I found a combination of R version and packages that do work. I would like to flag your suggestion as an answer but am not sure if this would be correct since it is more of a work-around. Maybe someone can advice on this. – Frederick Sep 05 '19 at 07:55
  • Seems reasonable to expect a function being plotted on a log scale to detect a zero value and exclude it. I'd contact the maintainer and ask for better error checking. – IRTFM Sep 15 '19 at 19:18
0

Here's what I think should have been done:

#identify the proper destination for the issue
 maintainer("survminer")
[1] "Alboukadel Kassambara <alboukadel.kassambara@gmail.com>"

Compose an email and send it:

Subject = " Blank plot with "cloglog" option to ggsurvplot"

Body = c("Please see the recent StackOverflow dialog on this issue.",
"https://stackoverflow.com/questions/57791504/in-r-survminerggsurvplot-with-fun-cloglog-returns-warning-message-and-emp/57793157#57793157",
"I suggest error trapping for the possibility of a zero value on the time axis.",
"Sincerely;")

And I did send it.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thank you for your suggestion. As you probably saw from my included links, I have been in contact with the developer and he is aware of the issue. Apparently, he doesn’t think of this as an issue that needs immediate attention (unfortunately). Maybe your email will help in this. Thanks! – Frederick Sep 15 '19 at 19:58
  • One would have hoped that such an obvious error would be trapped and worked around gracefully. – IRTFM Sep 16 '19 at 01:38