1

在 R Studio 中,当我添加截距线时,我的风险表会从我的生存图中删除。有没有办法克服这个问题?我的初始代码,显示风险表是:

    library(readxl)
    library(ggplot2)
    library(survival)
    library(survminer)
    library(gmodels) 
    library(tidyverse)

    demo2<-read_excel('data.xlsx',sheet=1)

    #tte1=time to event 1
    tte1<-read_excel("data.xlsx", sheet=1)
    tte1$group<-factor(tte1$group,levels=c("C","I")) #turn group into a factor, and sets order of         
    levels

    #Kaplan-Meier plot for event
    fit1 <- survfit(Surv(Time, Event) ~ group,data = tte1)
    summary(fit1)
    p<-ggsurvplot(fit1, data = tte1, 
                  risk.table = TRUE, #adds risk table
                  risk.table.title = "Number at risk",
                  risk.table.subtitle = " ",
                  cumcensor.title= " ",
                  conf.int = TRUE,   #adds shading
                  surv.scale="percent",
                  censor= FALSE,
                  conf.int.style= 'ribbon',
                  legend.title= '',
                  legend.labs = c("Control", "Intervention"),
                  break.time.by=60,  #adds intervals
                  tables.theme = theme_cleantable(), # theme for tables
                  tables.y.text = FALSE,
                  xlim=c(0,290),
                  surv.plot.height= 0.75,
                  risk.table.height=0.1
    )
    p+xlab("Time (days)")

但是当我更改这段代码的最后一行添加截取线时,风险表突然消失了。为了添加 incept 行,我将最后一行代码从 更改p+xlab("Time (days)")

    p$plot+geom_vline(xintercept = 186, linetype="dashed",
                      color = "black", size=1.0, label= "median")+ 
      geom_text(aes(x=225, y=.20, label="Median follow-up time"), size=5, family="sans", 
    fontface="plain")

有谁知道在不丢失风险表的情况下添加截距线的方法?

谢谢!

4

1 回答 1

1

请参阅下面的可重现示例:

library(survminer)
require("survival")
fit3 <- survfit( Surv(time, status) ~ sex,
                     data = colon )

ggsurv <- ggsurvplot(fit3, data = colon,conf.int = FALSE,
       risk.table = TRUE, ggtheme = theme_bw())

ggsurv$plot+geom_vline(xintercept=1000)
# no risk table

您必须更改$plotggsurv下的元素,

ggsurv$plot = ggsurv$plot+geom_vline(xintercept=1000)
print(ggsurv)

在此处输入图像描述

于 2020-01-10T22:54:06.037 回答