Why can I not do KM-curves in ggsurvplot? I do not have differing number of rows.

library(survival)
library(survminer)

fictive datafram

days_alive_within_30days <- c(14, 30, 5, 30, 30, 10, 30, 30)
mortality_30d <- factor(c("Dead", "Alive", "Dead", "Alive", "Alive","Dead", "Alive", "Alive"))
IHT_data_30 <- data.frame(cbind(days_alive_within_30days, mortality_30d ))

Make surv objects

km_fit <- survfit(Surv(days_alive_within_30days, mortality_30d) ~ 1)

summary

summary(km_fit)
Call: survfit(formula = Surv(days_alive_within_30days, mortality_30d) ~
1)

time n.risk n.event Pr((s0)) Pr(Dead)
5 8 1 0.875 0.125
10 7 1 0.750 0.250
14 6 1 0.625 0.375

Plot the KM curve with ggplot2

ggsurvplot(km_fit, data = data.frame(time = time, status = status), conf.int = FALSE)
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 4, 0, 8

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.