kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
490 stars 160 forks source link

Wrongly looking ggsurvplot with facet.by #304

Open dmiftakhutdinov opened 6 years ago

dmiftakhutdinov commented 6 years ago

Expected behavior

Two survival plots, one with step for X = 1, and one without step for X = 2

Actual behavior

First two commands: "Error in allf[[1]] : subscript out of bounds" occurs in strata function Third command: the second plot looks wrongly: only censoring symbol @ (20, 1.0) displayed.

It should be noted that the following works perfect:

ggsurvplot(npsurv(Surv(Time, Dead) ~ X, x))

Steps to reproduce the problem

x <- data.frame(Time = c(10, 20, 20, 20), Dead = c(TRUE, FALSE, FALSE, FALSE), X = c(1, 1, 2, 2), Q = c(1, 1, 1, 1))
ggsurvplot(npsurv(Surv(Time, Dead) ~ 1, x), facet.by = "X")
ggsurvplot(npsurv(Surv(Time, Dead) ~ X, x), facet.by = "X")
ggsurvplot(npsurv(Surv(Time, Dead) ~ Q, x), facet.by = "X")

session_info()

Session info ------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.3 (2017-03-06)
 system   x86_64, mingw32             
 ui       RStudio (1.0.136)           
 language (EN)                        
 collate  English_United States.1252  
 tz       America/New_York            
 date     2018-04-30                  

Packages ----------------------------------------------------------------------------------------------------------------
 package      * version  date       source        
 acepack        1.4.1    2016-10-29 CRAN (R 3.3.3)
 assertthat     0.2.0    2017-04-11 CRAN (R 3.3.3)
 backports      1.1.2    2017-12-13 CRAN (R 3.3.3)
 base         * 3.3.3    2017-03-06 local         
 base64enc      0.1-3    2015-07-28 CRAN (R 3.3.2)
 bindr          0.1.1    2018-03-13 CRAN (R 3.3.3)
 bindrcpp       0.2.2    2018-03-29 CRAN (R 3.3.3)
 broom          0.4.4    2018-03-29 CRAN (R 3.3.3)
 checkmate      1.8.5    2017-10-24 CRAN (R 3.3.3)
 cluster        2.0.5    2016-10-08 CRAN (R 3.3.3)
 cmprsk         2.2-7    2014-06-17 CRAN (R 3.3.3)
 codetools      0.2-15   2016-10-05 CRAN (R 3.3.2)
 colorspace     1.3-2    2016-12-14 CRAN (R 3.3.3)
 data.table     1.10.4-3 2017-10-27 CRAN (R 3.3.3)
 datasets     * 3.3.3    2017-03-06 local         
 devtools       1.13.5   2018-02-18 CRAN (R 3.3.3)
 digest         0.6.15   2018-01-28 CRAN (R 3.3.3)
 dplyr          0.7.4    2017-09-28 CRAN (R 3.3.3)
 foreign        0.8-70   2018-04-23 CRAN (R 3.3.3)
 Formula      * 1.2-1    2015-04-07 CRAN (R 3.3.2)
 ggplot2      * 2.2.1    2016-12-30 CRAN (R 3.3.3)
 ggpubr       * 0.1.6    2017-11-14 CRAN (R 3.3.3)
 glue           1.2.0    2017-10-29 CRAN (R 3.3.3)
 graphics     * 3.3.3    2017-03-06 local         
 grDevices    * 3.3.3    2017-03-06 local         
 grid           3.3.3    2017-03-06 local         
 gridExtra      2.3      2017-09-09 CRAN (R 3.3.3)
 gtable         0.2.0    2016-02-26 CRAN (R 3.3.3)
 Hmisc        * 4.1-1    2018-01-03 CRAN (R 3.3.3)
 htmlTable      1.11.2   2018-01-20 CRAN (R 3.3.3)
 htmltools      0.3.6    2017-04-28 CRAN (R 3.3.3)
 htmlwidgets    1.2      2018-04-19 CRAN (R 3.3.3)
 km.ci          0.5-2    2009-08-30 CRAN (R 3.3.3)
 KMsurv         0.1-5    2012-12-03 CRAN (R 3.3.2)
 knitr          1.20     2018-02-20 CRAN (R 3.3.3)
 labeling       0.3      2014-08-23 CRAN (R 3.3.2)
 lattice      * 0.20-34  2016-09-06 CRAN (R 3.3.3)
 latticeExtra   0.6-28   2016-02-09 CRAN (R 3.3.3)
 lazyeval       0.2.1    2017-10-29 CRAN (R 3.3.3)
 magrittr     * 1.5      2014-11-22 CRAN (R 3.3.3)
 MASS           7.3-45   2016-04-21 CRAN (R 3.3.3)
 Matrix         1.2-8    2017-01-20 CRAN (R 3.3.3)
 MatrixModels   0.4-1    2015-08-22 CRAN (R 3.3.3)
 memoise        1.1.0    2017-04-21 CRAN (R 3.3.3)
 methods      * 3.3.3    2017-03-06 local         
 mnormt         1.5-5    2016-10-15 CRAN (R 3.3.2)
 multcomp       1.4-8    2017-11-08 CRAN (R 3.3.3)
 munsell        0.4.3    2016-02-13 CRAN (R 3.3.3)
 mvtnorm        1.0-7    2018-01-25 CRAN (R 3.3.3)
 nlme           3.1-131  2017-02-06 CRAN (R 3.3.3)
 nnet           7.3-12   2016-02-02 CRAN (R 3.3.3)
 parallel       3.3.3    2017-03-06 local         
 pillar         1.2.2    2018-04-26 CRAN (R 3.3.3)
 pkgconfig      2.0.1    2017-03-21 CRAN (R 3.3.3)
 plyr           1.8.4    2016-06-08 CRAN (R 3.3.3)
 polspline      1.1.12   2015-07-14 CRAN (R 3.3.2)
 profvis        0.3.5    2018-02-22 CRAN (R 3.3.3)
 psych          1.8.3.3  2018-03-30 CRAN (R 3.3.3)
 purrr          0.2.4    2017-10-18 CRAN (R 3.3.3)
 quantreg       5.35     2018-02-02 CRAN (R 3.3.3)
 R6             2.2.2    2017-06-17 CRAN (R 3.3.3)
 RColorBrewer   1.1-2    2014-12-07 CRAN (R 3.3.2)
 Rcpp           0.12.16  2018-03-13 CRAN (R 3.3.3)
 reshape2       1.4.3    2017-12-11 CRAN (R 3.3.3)
 rlang          0.2.0    2018-02-20 CRAN (R 3.3.3)
 rms          * 5.1-2    2018-01-07 CRAN (R 3.3.3)
 rpart          4.1-10   2015-06-29 CRAN (R 3.3.3)
 rstudioapi     0.7      2017-09-07 CRAN (R 3.3.3)
 sandwich       2.4-0    2017-07-26 CRAN (R 3.3.3)
 scales         0.5.0    2017-08-24 CRAN (R 3.3.3)
 SparseM      * 1.76     2017-03-09 CRAN (R 3.3.3)
 splines        3.3.3    2017-03-06 local         
 stats        * 3.3.3    2017-03-06 local         
 stringi        1.1.7    2018-03-12 CRAN (R 3.3.3)
 stringr        1.2.0    2017-02-18 CRAN (R 3.3.3)
 survival     * 2.40-1   2016-10-30 CRAN (R 3.3.3)
 survminer    * 0.4.2    2018-01-31 CRAN (R 3.3.3)
 survMisc       0.5.4    2016-11-23 CRAN (R 3.3.3)
 TH.data        1.0-8    2017-01-23 CRAN (R 3.3.3)
 tibble         1.4.2    2018-01-22 CRAN (R 3.3.3)
 tidyr          0.8.0    2018-01-29 CRAN (R 3.3.3)
 tools          3.3.3    2017-03-06 local         
 utils        * 3.3.3    2017-03-06 local         
 withr          2.1.2    2018-03-15 CRAN (R 3.3.3)
 xtable         1.8-2    2016-02-05 CRAN (R 3.3.3)
 zoo            1.8-1    2018-01-08 CRAN (R 3.3.3)
dmiftakhutdinov commented 6 years ago

Seems to be the same as #254

dmiftakhutdinov commented 6 years ago

Things seems to be connected to .connect2origin: it doesn't fill variables columns when fit parameter is not supplied. The only thing here, I was studying ggsurvplot without facet.by as I needed this for particular task and wanted to use ggsurvplot()$plot + facet_wrap() instead. ggsurvplot()$plot$data contains wrong values for time = 0 because .connect2origin doesn't fill values when fit parameter is not supplied.

BingxinS commented 5 years ago

You are right, it was with the function .connect2origin() Here is a quick fix: https://github.com/BingxinS/survminer-fix

slyrus commented 3 years ago

The link to the quick fix above doesn't seem to point at anything useful and I'm seeing both the problem described and possibly a similar problem in my own code.

irenerlover commented 1 year ago

I also encountered a similar problem as slyrus...

alansz commented 10 months ago

I also have the same problem.