如何在 R 中的 ggfortify 中编辑图例

How to edit legend in ggfortify in R

我正在使用 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") 

我得到了这个结果:

如何将分层标签更改为种族?

而不是 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")