可重现示例:
require(Survival)
require(survminer)
require(ggplot2)
set.seed(42)
a <- c(32,291,545, 44,3,792,352, 20,615,169, 61,156, 88,863,255, 33,132,5,
63,8,964,831, 55,133, 12, 54,261,867, 17, 12,699,233,251,446, 43,223,
374, 75, 34, 69,120, 84,134,8,806,8, 48, 86,211, 2436, 61, 81, 87, 12,
838, 34, 17,141, 44,155,128,6, 29, 16, 16, 34,130,430,325, 41, 28, 53,
32,291,545, 44,3,792,352, 20,615,169, 61,156, 88,863,255, 33,132,5,
63,8,964,831, 55,133, 12, 54,261,867, 17, 12,699,233,251,446, 43,223,
86, 54,3,630, 93,699, 25,746,6, 46, 22, 60,395,402,151, 26, 38,125,
75, 34, 69,120, 84,134,8,806,8, 48, 86,211, 2436, 61,
191, 49, 59,6, 34, 56,2, 96, 422, 45, 70)
b <- sample(c("Alpha", "Beta", "Gamma"), length(a), replace = T)
c <- sample(0:1, length(a), replace = T)
df <- data.frame(a, b, c)
avg <- survfit(Surv(time = a, event = c) ~ 1, data = df)
survminer::ggsurvplot(
avg,
conf.int = FALSE,
censor = FALSE,
palette = "black",
linetype = "dashed"
)
surv_b <- survfit(Surv(time = a, event = c) ~ b, data = df)
survminer::ggsurvplot(
surv_b,
conf.int = FALSE,
censor = FALSE,
)
surv_comb <- c(avg, surv_b)
survminer::ggsurvplot_combine(
surv_comb,
data = df,
combine = TRUE,
censor = FALSE,
legend = "right"
)
两条生存曲线分别绘制,没有错误,但是当我尝试合并它们时,我得到一个错误,即 *!$运算符对原子向量无效 *。我已经用is.atomic()检查了几乎所有的东西,但我找不到问题的原因。有人能帮我找出这个问题吗?
1条答案
按热度按时间qrjkbowd1#
你需要做一个列表,把你的两个拟合放在里面,而不是把拟合连接起来。