问题描述
我想绘制一个kaplan meier曲线并用Weibull回归线覆盖它。 由于Weibull可以做出超出数据生存时间的预测,因此我想使Weibull回归线“更长”。我的问题是:当我设置X-asis限制了KM曲线结束时的编号结束(请参见下面的曲线)
这是我的代码:
car2 <- car2[-c(34:39,41,43),] # I only need this variables from the dataset
s1 <- with(car2,Surv(Time_OS_m,Event_OS)) #create survival object
fKM1 <- survfit(s1 ~ Eigenschap,data=car2) #Kaplan meier curve for s1
sWei1 <- survreg(s1 ~ as.factor(Eigenschap),dist='weibull',data=car2) #Weibull regression line
summary(sWei1)
pred.I1 = predict(sWei1,newdata=list(Eigenschap="SA"),type="quantile",p=seq(.01,.99,by=.01))
pred.I2 = predict(sWei1,newdata=list(Eigenschap="I"),by=.01))
df1 = data.frame(y=seq(.99,.01,by=-.01),Eigenschap1=pred.I1,Eigenschap2=pred.I2)
df_long1 = gather(df1,key= "Eigenschap",value="Time_OS_m",-y) #Convert to long data format
p = ggsurvplot(fKM1,data = car2,risk.table = TRUE,legend.title="",legend.labs = c("Infusion","Screenfailure/\napheresis only"),title = "Overall Survival (with Weibull distribution)",pval = TRUE,pval.coord = c(0,0.03),pval.size = 3.5,xlim = c(0,70)) #here i set the X axis limits
p$plot = p$plot + geom_line(data=df_long1,aes(x=Time_OS_m,y=y,group=Eigenschap))
p
上面的代码给出了这个图:
有人可以帮我把x轴一直编号到底吗,我在这里做错什么了?
解决方法
这可以通过参数break.x.by
实现。
使用survminer::ggsurvplot
中的第一个示例,请尝试以下操作:
library(survey)
library(survminer)
fit <- survfit(Surv(time,status) ~ sex,data = lung)
# Basic survival curves
ggsurvplot(fit,data = lung,xlim = c(0,1500))
ggsurvplot(fit,1500),break.x.by = 250)