在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)")
但是当我更改此代码的最后一行以添加拦截线时,风险表突然消失。要添加接收行,我将代码的最后一行从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")
有人知道在不丢失风险表的情况下添加拦截线的方法吗?
谢谢!
请参见下面的可复制示例:
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
您必须在ggsurv下更改$plot
元素,
ggsurv$plot = ggsurv$plot+geom_vline(xintercept=1000)
print(ggsurv)