1

我正在使用 carData::Rossi 数据来估计生存曲线。这是我用来生成绘图的代码:

library(carData); library(survival)
km1 <- survfit(Surv(week,arrest) ~ race,type = "kaplan-meier",data=Rossi)

library(ggplot2); library(ggfortify)
autoplot(km1) + 
  labs(x="Time", y="Proportion", strata= "Raza") 

我得到了这个结果:

在此处输入图像描述

如何将分层标签更改为 Race?

4

1 回答 1

4

而不是strata = "Raza",您同时使用color = "Raza"fill = "Raza"将有效。

library(GlobalDeviance)
library(ggfortify)

km1 <- survfit(Surv(week,arrest) ~ race,type = "kaplan-meier",data=Rossi)

autoplot(km1) + 
  labs(x="Time", y="Proportion", color = "Raza", fill = "Raza") 

在此处输入图像描述

我不确定这是否colour = "Raza"有效。它对我不起作用。

通过使用survminer::ggsurvplot

survminer::ggsurvplot(km1, xlab = "Time", ylab = "Proportion", 
                      legend.title = "Raza", conf.int = TRUE, ylim = c(0.65,1),
                      legend = "right", surv.scale = "percent")

在此处输入图像描述

于 2021-10-19T01:15:19.893 回答