secmalasct/survival.R
Jens Sauer 12ffcd4e38 survival: Change plot function to ggsurvplot
This will create the plot using the ggsurvplot from "survminer" package.
survminer user ggplot for plotting and comes with some powerful and nice
looking features.
2020-11-17 12:58:51 +01:00

57 lines
1.7 KiB
R

# secMalASCT survival calculation
#
# License: GPL version 3
# Jens Mathis Sauer (c) 2020
library(survival)
library(survminer)
source("utils.R")
secmal <- sma_load_data("current.csv")
# Setup survival object
surv_dx <- Surv(time = secmal$event_time_dx, event = secmal$event_status)
surv_asct <- Surv(time = secmal$event_time_asct, event = secmal$event_status)
# plot survival after diagnosis
sma_plot_surv_dx <- function() {
ggsurvplot(survfit(surv_dx ~ 1), data = secmal, xscale = "d_y",
title = "Survival after diagnosis",
break.time.by = 5 * 365.25)
}
# plot survival after diagnosis per sex
sma_plot_surv_dx_sex <- function() {
ggsurvplot(survfit(surv_dx ~ sex, data = secmal), data = secmal,
xscale = "d_y", title = "Survival after diagnosis",
legend.labs = c("Female", "Male"),
break.time.by = 5 * 365.25,
pval = TRUE)
}
# plot survival after transplantation
sma_plot_surv_asct <- function() {
ggsurvplot(survfit(surv_asct ~ 1), data = secmal, xscale = "d_y",
title = "Survival after transplantation",
break.time.by = 5 * 365.25)
}
# plot survival after transplantation per sex
sma_plot_surv_asct_sex <- function() {
ggsurvplot(survfit(surv_asct ~ sex, data = secmal), data = secmal,
xscale = "d_y", title = "Survival after transplantation",
legend.labs = c("Female", "Male"),
break.time.by = 5 * 365.25,
pval = TRUE)
}
#
# Write survival plots to files
#
sma_plot_file_surv <- function() {
sma_plot_file("survival_dx.png", png, sma_plot_surv_dx)
sma_plot_file("survival_dx_sex.png", png, sma_plot_surv_dx_sex)
sma_plot_file("survival_asct.png", png, sma_plot_surv_asct)
sma_plot_file("survival_asct_sex.png", png, sma_plot_surv_asct_sex)
}