Plots a survival curve from survfit object.

plot_surv(
  fit,
  type,
  legend.title = "Condition",
  legend.position = "right",
  xlab = "Day",
  add.median.survival = FALSE,
  add.conf.int = FALSE,
  add.pval = FALSE,
  p_adjust_method = "BH",
  ...
)

Arguments

fit

a survfit object, created by fit_surv()

type

character, either "survival" (a survival curve) or "mortality" (a mortality curve)

legend.title

character, the legend title. For no title, use legend.title = "". Default: "Condition"

legend.position

character, one of type "right", "left", "bottom", or "top". For in-plot legends, can be coordinates. c(0,0): bottom left, c(1,1): top right.

xlab

character, the x-axis label. Default: "Day"

add.median.survival

logical, whether to add the median survival line. Default: FALSE

add.conf.int

logical, whether to add confidence intervals. Default: FALSE

add.pval

logical, whether to add the p-value. Default: FALSE

p_adjust_method

character, either "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". Default: "BH". For details, see ?stats::p.adjust.

...

additional arguments passed to survminer::ggsurvplot(). See full list of arguments at survminer::ggsurvplot().

Value

A ggplot2 object plotted by the survminer package

Examples

# Convert bulk survival to individual survival
df_isurv <- get_indiv_surv(sample_data,
                           sample_order = c("WT", "Drug1", "Drug2"))
#> Joining with `by = join_by(x, condition, day, sex, status)`

# Fit survival object
surv_fit <- fit_surv(df_isurv)
#> 
#> call: formula = Surv(day, status) ~ condition

# Plot survival curve
plot_surv(fit = surv_fit, type = "survival")
#> Error in eval(fit$call$data): object 'df_isurv' not found