错误变量长度不同 ggsurvplot_facet

Error variable lengths differ ggsurvplot_facet

我正在尝试 运行 ggsurvplot_facet() 但无法通过 Error in model.frame.default(formula = surv_object2 ~ id, data = list( :variable lengths differ (found for 'id')。任何帮助将不胜感激。

我认为错误出在 survfit()/surv_fit() 组件中,而不是 ggsurvplot_facet() 组件中。

可以找到数据here

我的代码如下:

library(survival); library(survminer)

read.csv(file = 'test.csv', header = TRUE)

surv_object <- Surv(time = test$Days_survived, event = test$Event1) 
fit <- survfit(surv_object ~ id, data = test)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# I have also tried, without success
fit <- survfit(Surv(join$Days_survived, join$Event1) ~ id, data = join) 
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# and
fit <- survfit(as.formula(paste("Surv(join$Days_survived, join$Event1) ~", id)), data = join)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# and
fit <- survfit(as.formula(paste('Surv(join$Days_survived, join$Event1) ~', id)), data = join)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

# and
fit <- survfit(as.formula(Surv(join$Days_survived, join$Event1) ~ id), data=join)
ggsurvplot_facet(fit = fit, data = test, facet.by = "method", pval = TRUE)

我也使用 surv_fit() 函数尝试了上述所有组合。

我找到了类似的问题here and ,但我一直没能解决我的问题。

再次感谢。

这对我有用:

lapply(c("survival", "survminer"), require, character.only=TRUE)
df <- read.csv(file = 'test.csv', header = TRUE)
fit <- survfit(Surv(time = Days_survived, event = Event1) ~ id, data=df)
ggsurvplot_facet(fit, facet.by = "method", pval = TRUE, data = df)

结果: