0

我想将标签附加geom_dl到由ggsurvplot. 如果我使用ggsurvplot.

library(survival)
library(survminer)
library(directlabels)

fit <- survfit(Surv(time, status) ~ disease, data = kidney)
surv_km <- ggsurvplot(fit, risk.table = TRUE)
surv_km$plot + geom_dl(aes(label = gsub('disease=','',strata)), 
                       method = list(dl.trans(x = x + .2), "last.points"))

但是,如果我使用完整的surv_km

surv_km + geom_dl(aes(label = gsub('disease=','',strata)), 
                  method = list(dl.trans(x = x + .2), "last.points"))
>Error in surv_km + geom_dl(aes(label = gsub("disease=", "", strata)),  : 
  non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("+.ggsurv", "+.gg") for "+"
4

1 回答 1

1

使用%++%而不是+. 有关?add_ggsurvplot更多详细信息,请参阅。

fit <- survfit(Surv(time, status) ~ disease, data = kidney)
surv_km <- ggsurvplot(fit, risk.table = TRUE, legend = "none")
surv_km %++% geom_dl(aes(label = gsub('disease=','',strata)), 
                     method = list(dl.trans(x = x + .2), "last.points"))

在此处输入图像描述

要删除表格末尾的标签,我们可以分配surv_km[["table"]][["layers"]][[2]]NULL,例如

surv_km <- surv_km %++% 
               geom_dl(aes(label = gsub('disease=','',strata)), 
                       method = list(dl.trans(x = x + .2), "last.points"))
surv_km[["table"]][["layers"]][[2]]<-NULL

最后要删除disease=图形和/或表格的图例标签,请使用gsubwith names(fit$strata),如下所示

attr(fit$strata, "names") = gsub("disease=","",attr(fit$strata, "names"))
#then repeat above steps
于 2020-01-07T07:32:46.817 回答