survminer icon indicating copy to clipboard operation
survminer copied to clipboard

ggsurvplot does not plot every event

Open andrebolerbarros opened this issue 9 months ago • 0 comments

Hey everyone,

I was using a dataset of mine and realized ggsurvplot was not plotting all of the events occurring. I tried with the lung dataset and it happens as well.

I changed one of the events to occur at time 1100, which is not included in the default dataset. Only when I extend the limits of the plot does this event appear. Should the function plot based on "rounding" the time by excess (in this case, plotting up to 1200 or something)?

Expected behavior

image

Actual behavior

image

Steps to reproduce the problem

require("survival")
require(survminer)

df<-lung
df$status[6]<-2
df$time[6]<-1100

#View(df)

fit<- survfit(Surv(time, status) ~ sex, data = df)

f1<-ggsurvplot(fit, data = df)
f2<-ggsurvplot(fit, data = df,break.time.by=200,xlim=c(0,1100))

### `session_info()`

R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=Portuguese_Portugal.utf8  LC_CTYPE=Portuguese_Portugal.utf8   
[3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C                        
[5] LC_TIME=Portuguese_Portugal.utf8    

time zone: Europe/Lisbon
tzcode source: internal

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

other attached packages:
[1] survminer_0.4.9 ggpubr_0.6.0    ggplot2_3.4.4   survival_3.5-7 

loaded via a namespace (and not attached):
 [1] utf8_1.2.4         generics_0.1.3     tidyr_1.3.1       
 [4] rstatix_0.7.2      stringi_1.8.3      lattice_0.21-9    
 [7] digest_0.6.34      magrittr_2.0.3     evaluate_0.23     
[10] grid_4.3.2         fastmap_1.1.1      plyr_1.8.9        
[13] Matrix_1.6-5       backports_1.4.1    gridExtra_2.3     
[16] purrr_1.0.2        fansi_1.0.6        scales_1.3.0      
[19] abind_1.4-5        cli_3.6.2          KMsurv_0.1-5      
[22] rlang_1.1.3        munsell_0.5.0      splines_4.3.2     
[25] withr_3.0.0        yaml_2.3.8         tools_4.3.2       
[28] reshape2_1.4.4     ggsignif_0.6.4     dplyr_1.1.4       
[31] colorspace_2.1-0   km.ci_0.5-6        broom_1.0.5       
[34] vctrs_0.6.5        R6_2.5.1           zoo_1.8-12        
[37] lifecycle_1.0.4    stringr_1.5.1      car_3.1-2         
[40] pkgconfig_2.0.3    pillar_1.9.0       gtable_0.3.4      
[43] data.table_1.14.10 glue_1.7.0         Rcpp_1.0.12       
[46] xfun_0.41          tibble_3.2.1       tidyselect_1.2.0  
[49] rstudioapi_0.15.0  knitr_1.45         farver_2.1.1      
[52] xtable_1.8-4       survMisc_0.5.6     htmltools_0.5.7   
[55] labeling_0.4.3     rmarkdown_2.25     carData_3.0-5     
[58] compiler_4.3.2 

andrebolerbarros avatar May 10 '24 10:05 andrebolerbarros