Questions for the input of function survminer::ggsurvplot

Here is a reproducible exmaple.
km is a survfit object but the ggsurvplot function return this error:

#> Error in .get_data(fit, data = data, complain = FALSE): The `data` argument should be provided either to ggsurvfit or survfit.
time <- c(5, 6, 2, 4, 4) 
event <- c(1, 0, 0, 1, 1)
library(survival)
km <- survfit(Surv(time, event) ~ 1)
library(survminer)
#> 载入需要的程辑包:ggplot2
#> 载入需要的程辑包:ggpubr
#> 载入需要的程辑包:magrittr
ggsurvplot(km, conf.int = FALSE, risk.table = "nrisk_cumevents", legend = "none")
#> Error in .get_data(fit, data = data, complain = FALSE): The `data` argument should be provided either to ggsurvfit or survfit.

Created on 2018-12-25 by the reprex package (v0.2.1)

You are not passing data argument, try this

library(survival)
library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
events <- data.frame(time = c(5, 6, 2, 4, 4), 
                         event = c(1, 0, 0, 1, 1))
km <- survfit(Surv(time, event) ~ 1, data = events)
ggsurvplot(km, data = events, conf.int = FALSE, risk.table = "nrisk_cumevents", legend = "none")

Created on 2018-12-24 by the reprex package (v0.2.1)

4 Likes

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