【问题标题】:Rearranging legend order plotted using ggsurv for Kaplan Meier curves重新排列使用 ggsurv 绘制 Kaplan Meier 曲线的图例顺序
【发布时间】:2021-11-10 15:23:26
【问题描述】:

我为我的数据绘制了 Kaplan Meier 曲线,该曲线适用于 6 种不同的治疗方法,即:

  1. 100低
  2. 30 低
  3. 15低
  4. 100高
  5. 30高
  6. 15高

我希望我的图例按照我上面提到的顺序排列,但是当我绘制它时,它会给出图片中所附的图例。

我使用的代码如下。有人可以帮我解决如何重新排列图例表的顺序吗?

    #Kaplan-Meier curves to plot the result
ru <- survfit(Surv(Tf,fat==1) ~ Treatments, data = fat)

uu <- ggsurv(ru, CI = "def", plot.cens = TRUE, surv.col = c(1,1,2,2,3,3),
             cens.col = 1, lty.est = c(1,1,1,5,5,5), size.est = 1.05, cens.shape = 12, cens.size = 3,
             back.white = FALSE, xlab = "Time (seconds)", ylab = "Ratio of fish remaining", main = "Kaplan-Meier Curves")

uu1 <- uu + theme_gray(base_size=13) + theme(legend.position = "right") + theme(legend.title = element_text(face = "bold")) +
          theme(plot.title = element_text(face = "bold")) + theme(axis.title = element_text(size = 15, face = "bold")) +
  theme(axis.ticks = element_line(size = 1))  + scale_x_continuous(breaks = scales::pretty_breaks(n = 10)) +
  scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) + theme(axis.text = element_text(size = 14)) +
  theme(legend.text = element_text(size = 12))

windows()
(uu1)

这里的“Tf”是我的数据中的时间,它在数据框“fat”中

非常感谢您。

【问题讨论】:

    标签: r graph legend survival-analysis legend-properties


    【解决方案1】:

    您需要在模型之前重新排序Treatments,这里是tidyverse 方法:

    library(tidyverse)
    
    treat_order <- c("100Low","30Low","15Low","100High","30High","15High")
    
    fat <-
        fat %>% 
        mutate(Treatments = fct_relevel(Treatments,treat_order))
    

    【讨论】:

      猜你喜欢
      • 2020-11-03
      • 1970-01-01
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      相关资源
      最近更新 更多