0

我想重新排序 survfit 对象中的地层,以便图例标签以特定顺序出现在ggsurvplot.

例子:

fit <- survfit(Surv(time, status) ~ sex + ph.ecog, data = lung)
names(fit$strata)
[1] "sex=1, ph.ecog=0" "sex=1, ph.ecog=1" "sex=1, ph.ecog=2" "sex=1, ph.ecog=3"
 "sex=2, ph.ecog=0" "sex=2, ph.ecog=1" "sex=2, ph.ecog=2"

如何重新排序地层?例如,如果我的目标是:

names(fit$strata)
[1] "sex=1, ph.ecog=0" "sex=2, ph.ecog=0" "sex=1, ph.ecog=1" "sex=2, ph.ecog=1" 
"sex=1, ph.ecog=2" "sex=2, ph.ecog=2" "sex=1, ph.ecog=3"

编辑:我以这种方式重新排序了地层:

fit$strata <- fit$strata[order(factor(names(fit$strata),
levels = c("sex=1, ph.ecog=0", "sex=2, ph.ecog=0", "sex=1, ph.ecog=1",
"sex=2, ph.ecog=1", "sex=1, ph.ecog=2", "sex=2, ph.ecog=2",
 "sex=1, ph.ecog=3")))]

ggsurvplot但是,使用此修订版调用fit$strata会出现此错误:

Error in findInterval(ptimes, fit$time) : 
  'vec' must be sorted non-decreasingly and not contain NAs

对这个错误有什么建议吗?谢谢。

4

0 回答 0