survminer
survminer copied to clipboard
ggadjustedcurves() for dichotomized continuous variables does not work
Expected behavior
I have tried to plot the survival curves of a Cox model with ggadjustedcurves() selecting the expression of a miRNA (dichotomized as "low" and "high" expression) as grouping variable.
Actual behavior
I only get one curve in the plot corresponding to one of the groups. I would like to get a plot with both curves so I can see the differences in the survival as a function of a specific miRNA expression.
Steps to reproduce the problem
This is my code:
samples$discrete_miRNA <- cut(samples$specific_miRNA
,c(-Inf, cut_value, Inf),
labels= c("low", "high"))
full<-coxph(Surv(samples$time, samples$status) ~ miRNA + gender +age, data=samples)
ggadjustedcurves(stepwise, data=samples, variable="discrete_miRNA")
session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────
setting value
version R version 3.6.3 (2020-02-29)
os Ubuntu 18.04.5 LTS
system x86_64, linux-gnu
ui RStudio
language (EN)
collate es_ES.UTF-8
ctype es_ES.UTF-8
tz Europe/Madrid
date 2021-04-28
─ Packages ───────────────────────────────────────────────────────────────────────────────────
package * version date lib source
abind 1.4-5 2016-07-21 [1] CRAN (R 3.6.3)
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.3)
backports 1.2.1 2020-12-09 [1] CRAN (R 3.6.3)
broom 0.7.6 2021-04-05 [1] CRAN (R 3.6.3)
cachem 1.0.4 2021-02-13 [1] CRAN (R 3.6.3)
callr 3.6.0 2021-03-28 [1] CRAN (R 3.6.3)
car 3.0-10 2020-09-29 [1] CRAN (R 3.6.2)
carData 3.0-4 2020-05-22 [1] CRAN (R 3.6.2)
cellranger 1.1.0 2016-07-27 [1] CRAN (R 3.6.1)
cli 2.4.0 2021-04-05 [1] CRAN (R 3.6.3)
colorspace 2.0-0 2020-11-11 [1] CRAN (R 3.6.3)
cowplot 1.1.1 2020-12-30 [1] CRAN (R 3.6.3)
crayon 1.4.1 2021-02-08 [1] CRAN (R 3.6.3)
curl 4.3 2019-12-02 [1] CRAN (R 3.6.2)
data.table 1.14.0 2021-02-21 [1] CRAN (R 3.6.3)
DBI 1.1.1 2021-01-15 [1] CRAN (R 3.6.3)
desc 1.3.0 2021-03-05 [1] CRAN (R 3.6.3)
devtools 2.4.0 2021-04-07 [1] CRAN (R 3.6.3)
digest 0.6.27 2020-10-24 [1] CRAN (R 3.6.3)
dplyr 1.0.5 2021-03-05 [1] CRAN (R 3.6.3)
ellipsis 0.3.1 2020-05-15 [1] CRAN (R 3.6.2)
exactRankTests 0.8-32 2021-04-16 [1] CRAN (R 3.6.3)
fansi 0.4.2 2021-01-15 [1] CRAN (R 3.6.3)
farver 2.1.0 2021-02-28 [1] CRAN (R 3.6.3)
fastmap 1.1.0 2021-01-25 [1] CRAN (R 3.6.3)
forcats 0.5.1 2021-01-27 [1] CRAN (R 3.6.3)
foreign 0.8-76 2020-03-03 [4] CRAN (R 3.6.3)
fs 1.5.0 2020-07-31 [1] CRAN (R 3.6.3)
generics 0.1.0 2020-10-31 [1] CRAN (R 3.6.3)
ggplot2 * 3.3.3 2020-12-30 [1] CRAN (R 3.6.3)
ggpubr * 0.4.0 2020-06-27 [1] CRAN (R 3.6.3)
ggsignif 0.6.1 2021-02-23 [1] CRAN (R 3.6.3)
ggtext 0.1.1 2020-12-17 [1] CRAN (R 3.6.3)
glue 1.4.1.9000 2021-04-09 [1] Github (jimhester/fstrings@f0a7b2a)
gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.2)
gridtext 0.1.4 2020-12-10 [1] CRAN (R 3.6.3)
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.1)
haven 2.3.1 2020-06-01 [1] CRAN (R 3.6.2)
hms 1.0.0 2021-01-13 [1] CRAN (R 3.6.3)
insight 0.13.2 2021-04-01 [1] CRAN (R 3.6.3)
km.ci 0.5-2 2009-08-30 [1] CRAN (R 3.6.3)
KMsurv 0.1-5 2012-12-03 [1] CRAN (R 3.6.3)
knitr 1.31 2021-01-27 [1] CRAN (R 3.6.3)
labeling 0.4.2 2020-10-20 [1] CRAN (R 3.6.3)
lattice 0.20-41 2020-04-02 [4] CRAN (R 3.6.3)
lifecycle 1.0.0 2021-02-15 [1] CRAN (R 3.6.3)
magrittr 2.0.1 2020-11-17 [1] CRAN (R 3.6.3)
markdown 1.1 2019-08-07 [1] CRAN (R 3.6.1)
Matrix 1.3-2 2021-01-06 [1] CRAN (R 3.6.3)
maxstat 0.7-25 2017-03-02 [1] CRAN (R 3.6.3)
memoise 2.0.0 2021-01-26 [1] CRAN (R 3.6.3)
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.1)
mvtnorm 1.1-1 2020-06-09 [1] CRAN (R 3.6.3)
openxlsx 4.2.3 2020-10-27 [1] CRAN (R 3.6.3)
pillar 1.5.1 2021-03-05 [1] CRAN (R 3.6.3)
pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 3.6.3)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
pkgload 1.2.1 2021-04-06 [1] CRAN (R 3.6.3)
plyr 1.8.6 2020-03-03 [1] CRAN (R 3.6.2)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2)
pROC * 1.17.0.1 2021-01-13 [1] CRAN (R 3.6.3)
processx 3.5.1 2021-04-04 [1] CRAN (R 3.6.3)
ps 1.6.0 2021-02-28 [1] CRAN (R 3.6.3)
purrr 0.3.4 2020-04-17 [1] CRAN (R 3.6.2)
R6 2.5.0 2020-10-28 [1] CRAN (R 3.6.3)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.1)
Rcpp 1.0.6 2021-01-15 [1] CRAN (R 3.6.3)
readxl 1.3.1 2019-03-13 [1] CRAN (R 3.6.1)
remotes 2.3.0 2021-04-01 [1] CRAN (R 3.6.3)
rio 0.5.26 2021-03-01 [1] CRAN (R 3.6.3)
rJava 0.9-13 2020-07-06 [1] CRAN (R 3.6.3)
rlang 0.4.10 2020-12-30 [1] CRAN (R 3.6.3)
rprojroot 2.0.2 2020-11-15 [1] CRAN (R 3.6.3)
rstatix 0.7.0 2021-02-13 [1] CRAN (R 3.6.3)
scales 1.1.1 2020-05-11 [1] CRAN (R 3.6.2)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.3)
sjlabelled 1.1.7 2020-09-24 [1] CRAN (R 3.6.3)
sjmisc * 2.8.6 2021-01-07 [1] CRAN (R 3.6.3)
stringi 1.5.3 2020-09-09 [1] CRAN (R 3.6.3)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1)
survival * 3.2-7 2020-09-28 [4] CRAN (R 3.6.3)
survminer * 0.4.9 2021-03-09 [1] CRAN (R 3.6.3)
survMisc 0.5.5 2018-07-05 [1] CRAN (R 3.6.3)
testthat 3.0.2 2021-02-14 [1] CRAN (R 3.6.3)
tibble 3.1.0 2021-02-25 [1] CRAN (R 3.6.3)
tidyr 1.1.3 2021-03-03 [1] CRAN (R 3.6.3)
tidyselect 1.1.0 2020-05-11 [1] CRAN (R 3.6.2)
usethis 2.0.1 2021-02-10 [1] CRAN (R 3.6.3)
utf8 1.2.1 2021-03-12 [1] CRAN (R 3.6.3)
vctrs 0.3.7 2021-03-29 [1] CRAN (R 3.6.3)
withr 2.4.1 2021-01-26 [1] CRAN (R 3.6.3)
xfun 0.22 2021-03-11 [1] CRAN (R 3.6.3)
xlsx * 0.6.5 2020-11-10 [1] CRAN (R 3.6.3)
xlsxjars 0.6.1 2014-08-22 [1] CRAN (R 3.6.3)
xml2 1.3.2 2020-04-23 [1] CRAN (R 3.6.2)
xtable 1.8-4 2019-04-21 [1] CRAN (R 3.6.1)
zip 2.1.1 2020-08-27 [1] CRAN (R 3.6.3)
zoo 1.8-9 2021-03-09 [1] CRAN (R 3.6.3)
[1] /home/asierfp1996/R/x86_64-pc-linux-gnu-library/3.6 [2] /usr/local/lib/R/site-library [3] /usr/lib/R/site-library [4] /usr/lib/R/library
The same would happend with age. Applying the same procedure that is explained here (https://rpkgs.datanovia.com/survminer/survminer_cheatsheet.pdf) I got only one curve for a specific age group (and not different curves for each age group).
Code:
samples$age4 <- cut(samples$age, c(10,65,100)) ggadjustedcurves(cox_model, data=samples, variable="age4")
I know this is an old post, but the problem is that you are using the continuous version of the variable miRNA
in the coxph
model. If you want to have curves stratified by the discrete_miRNA
variable, you have to include the dichotomized version in the coxph
model instead.
You probably don't want to do this though, because this would result in a loss of information (and even systematic bias sometimes). I am currently working on an R-Package that directly plots the effect of continuous covariates on a time-to-event endpoint. If you are still interested in this problem, I can inform you once it is published.
Sure, that would be great! Thanks a lot for the answer!
I am hereby informing you that I finally published the R-Package I was talking about (with an associated preprint article). The R-Package can be found here: https://github.com/RobinDenz1/contsurvplot And the preprint describing the methodology behind it can be accessed on arXiv: https://arxiv.org/abs/2208.04644
You could do something like:
library(contsurvplot)
library(survival)
model <- coxph(Surv(time, status) ~ miRNA + gender + age, data=samples, x=TRUE)
plot_surv_area(time="time", status="status", variable="miRNA", data=samples, model=model)
or maybe:
plot_surv_contour(time="time", status="status", variable="miRNA", data=samples, model=model)
If you have any questions, comments or suggestions please let me know!