我正在尝试使用 R 中的 survminer 包创建生存图,其中数据按基因突变分割,并包含代表各个方面的所有个体的汇总线。当不使用 ggsurvplot 中的 add.all 进行多组(按性别和突变类型划分)时,生存分析和绘图工作正常。但是,当尝试使用 add.all = TRUE 添加跨方面的组合生存曲线时,它不会按预期显示。以下是使用肺部数据集的最小可重复示例:
示例:
library(survival) ; library(survminer)
set.seed(102030)
lung <- lung %>% mutate( mut = sample(c("mutA","mutB"), nrow(lung), replace = T, prob = c(0.5,0.5))) # create 2 groups for demo
# Basic survival curves
fit1 <- survfit(Surv(time, status) ~ 1 , data = lung) # general overall survival
ggsurvplot(fit1 , data = lung)
# Basic survival curves with 2 groups for sex
fit2 <- survfit(Surv(time, status) ~ sex , data = lung)
ggsurvplot(fit2 , data = lung)
# Survival curves with 2 variables and 2 groups per variable (problematic part)
fit3 <- survfit(Surv(time, status) ~ sex + mut, data = lung)
ggsurvplot(fit3 , data = lung, facet.by = "mut") # example one facet by mut. Works as intended!
ggsurvplot(fit3 , data = lung,
facet.by = "mut",
add.all = T) # supposedly should have added a third groups (i.e. a line that represents the number of individuals in each facet)
# I also tried this approach, but this is not faceting the plot either.
ggsurvplot_combine(
list(fit1, fit3),
list(lung, lung),
facet.by = "mut",
pval = TRUE,
risk.table = TRUE,
conf.int = F,
palette = "jco"
)
我希望 add.all = TRUE 参数在各个面上添加一条汇总曲线,但这不会发生。我该如何解决这个问题或者功能是否有限制? 我可能需要以不同的方式使用
ggsurvplot_group_by
或 ggsurvplot_facet
。
由于 survminer 中尚未实现分面(或分组)和添加总组 (add.all=TRUE),因此您可以单独绘制曲线,然后使用
arrange_ggsurvplots
将它们组合起来。
pA <- ggsurvplot(fit3, title="Mutant A",
add.all=TRUE,
data = subset(lung, subset=mut=="mutA")); pA
pB <- ggsurvplot(fit3, add.all=TRUE, title="Mutant B",
data = subset(lung, subset=mut=="mutB"))
pAB <- arrange_ggsurvplots(list(pA, pB))
ggsave("pAB.png", pAB, width=10, height=5)