我使用下面的脚本绘制Kaplan-Meier曲线。
我认为中位生存线是一个很好的工具。但是,中位生存线绘制为黑色虚线,从图形上来说是压倒性的。我可以更改生存线的颜色或不透明度以减少surv.median.line函数的图形输出吗?
如果没有,是否可以手动添加垂直/水平中值存活线,以更改颜色或不透明度?
j <- ggsurvplot(
fit,
data = p,
#fun="cumhaz",
risk.table = "abs_pct", #risk.table.col="strata",
pval = TRUE,
pval.coord = c(0, 0.25),
conf.int = T,
#legend.labs=c("0-4%", "5-9%", "\u226510%"),
cumevents.title = "Cumulative number of recurrences",
size=c(0.8,0.8,0.8,0.8),
xlim = c(0,10),
alpha=0.8,
break.x.by = 1,
xlab="Time in years",
ylab="Probability of progression-free survival",
ggtheme = theme_gray(),
risk.table.y.text.col = T,
risk.table.y.text = TRUE,
surv.median.line = "hv",
ylim=c(0,1),
cumevents=TRUE,
#palette=c("#222a37","darkred"),
surv.scale="percent")
j
我尝试添加以下内容,但收到此警告: max(surv_median)中的错误:参数的无效“类型”(关闭)
surv_median <- as.vector(summary(fit)$table[, "median"])
df <- data.frame(x1 = surv_median, x2 = surv_median,
y1 = rep(0, length(surv_median)), y2 = rep(0.5, length(surv_median)))
j$plot <- j$plot +
geom_segment(aes(x = 0, y = 0.5, xend = max(surv_median), yend = 0.5),
linetype = "dashed", size = 0.5)+ # horizontal segment
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = df,
linetype = "dashed", size = 0.5) # vertical segments
print(j)
答案 0 :(得分:1)
As of today,似乎没有直接的方法可以改变生存中线。
这是上面代码的片段,用于绘制线条。
if(nrow(df)>0){
if(type %in% c("hv", "h"))
p <- p +
geom_segment(aes(x = 0, y = max(y2), xend = max(x1), yend = max(y2)),
data = df, linetype = "dashed", size = 0.5) # horizontal segment
if(type %in% c("hv", "v"))
p <- p + geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = df,
linetype = "dashed", size = 0.5) # vertical segments
}
else warning("Median survival not reached.")
}
您所能做的就是不要画线并手动添加,而是从代码中学习如何计算。还有一种方法可以破解该函数以使其在ggsurvplot
函数之外运行。我将通过获得对正在绘制的数据的访问权,然后添加自己的geom_segment
来解决这个问题。