Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upggsurvplot and cox model #109
Comments
|
This error is reproducible using the heart data in the survival package library(survival)
library(survminer)
cox_heart <- coxph(Surv(start, stop, event) ~ age + surgery + strata(transplant), heart)
newdata = data.frame(age = c(50, 50), surgery = c(1, 1), transplant = c("0", "1"))
surv <- survfit(cox_heart, newdata=newdata)
qq <- ggsurvplot(surv,
fun = "event",
censor = FALSE,
risk.table = "absolute",
legend = "bottom",
legend.title = "Transplant",
legend.labs = c("Yes", "No"),
risk.table.col = "strata",
risk.table.y.text.col = TRUE,
risk.table.y.text = FALSE,
conf.int = TRUE,
conf.int.style = "step",
palette = "Dark2"
)
qq |
|
The error is caused by color scales.
For cox model the Is the |
|
Thank you for this very good diagnostic! I should work on optimizing ggsurvplot() in handling the outputs of survfit.coxph()! |
|
Regarding coxph models, |
|
Hi @pbiecek , I'm not working on it.. So, it would be great if you can convert it and include it to survminer:-)! |
|
Now, Example: library(survival)
res.cox <- coxph(Surv(time, status) ~ age + strata(sex) + ph.ecog, data = lung)
sex_df <- with(lung,
data.frame(sex = c(1, 2),
age = rep(mean(age, na.rm = TRUE), 2),
ph.ecog = c(1, 1)
)
)
fit <- survfit(res.cox, newdata = sex_df)
library(survminer)
ggsurvplot(fit, conf.int = TRUE, legend.labs=c("Sex=1", "Sex=2"),
risk.table = TRUE,
palette = "Dark2",
ggtheme = theme_minimal()) |

(e-mail from a survminer user)
Great package. I've got the cumulative incidence curve almost as I want to. It's just That I would like to change color of my two prediced curves. I've tried many different palette = "x", including "Dark2" and "RdBu", but only "hue" works, the others return
Error:
breaksandlabelsmust have the same lengthI base the curve on a coxph-object (i.e. predict.survfit.coxph) and also include strata() in the cox formula and use Surv(time1, time2, event) to allow late entry. I've checked so the curves are correct and the risk-table is correct too. But I really would like to change the color.
I attach the output and present the code bellow.
Would be very grateful if you could have a look.
b_strat_F_adj <- coxph(Surv(time, time_stop, outcome7) ~ strata(Fina) + psa_log*age_entry + age_entry + psa_log + PrevNegBiopsy, data = b1)
newdata <- data.frame(Fina = c(1, 0), PrevNegBiopsy = c(0, 0), age_entry = c(60, 60), psa_log = c(1, 1))
surv <- survfit(b_strat_F_adj, newdata=newdata)
qq <- ggsurvplot(surv,
fun = "event",
ylim = c(0, .03),
censor = FALSE,
risk.table = "absolute",
legend = "bottom",
legend.title = "Finasteride",
legend.labs = c("Yes", "No"),
risk.table.col = "strata",
risk.table.y.text.col = TRUE,
risk.table.y.text = FALSE,
conf.int = TRUE,
conf.int.style = "step",
# palette = "Dark2")