Survival Analysis: Error in ggsurvfit(.) : could not find function "ggsurvfit"

I’m running the survival analysis in R from the following tutorial: https://www.emilyzabor.com/tutorials/survival_analysis_in_r_tutorial.html#Part_1:_Introduction_to_Survival_Analysis

I got an error while running the following lines of code to get Kaplan-Meier plots.

survfit2(Surv(time, status) ~ 1, data = lung) %>% 
  ggsurvfit() +
  labs(
    x = "Days",
    y = "Overall survival probability"
  )

Error in ggsurvfit(.) : could not find function "ggsurvfit"

Could anyone help me figure out how to fix the error? I’d appreciate it!

>Solution :

It seems you haven’t downloaded the package, so you can use

install.packages("ggsurvfit")

or

remotes::install_github("ddsjoberg/ggsurvfit")

*the second command also requires a package (remotes).

Leave a Reply