jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
718 stars 147 forks source link

Missing censor points on survival plot #742

Closed ksnap28 closed 1 year ago

ksnap28 commented 2 years ago

I started using your package recently for interactive survival plots and it has been wonderful. Thank you!

I did notice that in instances where multiple individuals are censored at the same time point, a censor tick does not appear on the chart. In the example provided below, I would expect a censor tick to appear at 30, 40, 50, 60, 70, 80, 100, 120, & 200. However they do not appear at 40, 70, or 80.

I believe I've identified the fix and will submit a pull request for you to review.

survival_data =
    data.frame(event_status = c(rep(1, 8),
                                                 rep(0, 12)),
                      time_to_event = c(10, 20, 30, 40, 40, 90, 90, 150,
                                                    30, 40, 40, 50, 60, 70, 70, 80, 80, 100, 120, 200))

survival_fit =
    survival::survfit(survival::Surv(time_to_event, event_status == 1) ~ 1,
                      data = survival_data)

highcharter::hchart(survival_fit)

Here is my session information:

sessionInfo() R version 4.1.1 (2021-08-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252

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

loaded via a namespace (and not attached): [1] zoo_1.8-9 tidyselect_1.1.1 xfun_0.26 purrr_0.3.4 splines_4.1.1 lattice_0.20-44 vctrs_0.3.8
[8] generics_0.1.0 htmltools_0.5.2 yaml_2.2.1 utf8_1.2.2 survival_3.2-13 rlang_0.4.11 R.oo_1.24.0
[15] pillar_1.6.2 glue_1.4.2 DBI_1.1.1 R.utils_2.11.0 TTR_0.24.2 lifecycle_1.0.0 quantmod_0.4.18
[22] stringr_1.4.0 R.methodsS3_1.8.1 highcharter_0.8.2 htmlwidgets_1.5.4 evaluate_0.14 knitr_1.34 fastmap_1.1.0
[29] curl_4.3.2 fansi_0.5.0 broom_0.7.9 xts_0.12.1 Rcpp_1.0.7 backports_1.2.1 jsonlite_1.7.2
[36] digest_0.6.27 stringi_1.7.4 rlist_0.4.6.2 dplyr_1.0.7 grid_4.1.1 tools_4.1.1 magrittr_2.0.1
[43] tibble_3.1.4 crayon_1.4.1 tidyr_1.1.3 pkgconfig_2.0.3 ellipsis_0.3.2 Matrix_1.3-4 data.table_1.14.0 [50] lubridate_1.7.10 assertthat_0.2.1 rmarkdown_2.11 rstudioapi_0.13 R6_2.5.1 igraph_1.2.6 compiler_4.1.1

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Feel free to reopen it if you find it necessary.