ggfortify 不支持 survfit 多个协变量?

ggfortify doesn't support survfit multiple covariables?

以下示例是通过添加 "age"

从文档示例修改的
d.coxph <- (survfit(Surv(time, status) ~ sex+age, data = lung))
autoplot(d.coxph)

我会收到以下错误:

Error in levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : factor level [41] is duplicated

Enter a frame number, or 0 to exit

1: autoplot(d.coxph)> Error in levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : factor level [41] is duplicated

Enter a frame number, or 0 to exit

1: autoplot(d.coxph) 2: autoplot.survfit(d.coxph) 3: fortify(object, surv.connect = surv.connect, fun = fun) 4: fortify.survfit(object, surv.connect = surv.connect, fun = fun) 5: factor(rep(groupIDs, model$strata), levels = groupIDs)

2: autoplot.survfit(d.coxph) 3: fortify(object, surv.connect = surv.connect, fun = fun) 4: fortify.survfit(object, surv.connect = surv.connect, fun = fun) 5: factor(rep(groupIDs, model$strata), levels = groupIDs)

一个可能的解决方案是将连续变量age分门别类,并在survfit公式中考虑性别和年龄的交互作用:

library(survival)
data(lung)
lung$age2cat <- cut(lung$age,breaks=2)
lung$sex <- factor(lung$sex, labels=c("F","M"))
d.coxph <- survfit(Surv(time, status) ~ interaction(sex,age2cat), data = lung)

autoplot(d.coxph, conf.int=F, surv.size=1)