diff --git a/README.md b/README.md index 4e984b1..ceeb332 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,4 @@ secMalASCT statistical analysis R packages used --------------- * tidyverse +* survminer diff --git a/survival.R b/survival.R index 3d275c4..49535fc 100644 --- a/survival.R +++ b/survival.R @@ -4,6 +4,7 @@ # Jens Mathis Sauer (c) 2020 library(survival) +library(survminer) source("utils.R") secmal <- sma_load_data("current.csv") @@ -14,38 +15,46 @@ surv_asct <- Surv(time = secmal$event_time_asct, event = secmal$event_status) # plot survival after diagnosis sma_plot_surv_dx <- function() { - plot(survfit(surv_dx ~ 1), mark.time = TRUE, xscale = 365.25, - xlab = "Years", ylab = "Survival") - title("Kaplan-Meier estimate for\nsecMalASCT study", - "Survival after diagnosis") + ggsurvplot(survfit(surv_dx ~ 1), data = secmal, xscale = "d_y", + title = "Survival after diagnosis", + break.time.by = 5 * 365.25, + surv.median.line = "hv", + risk.table = "abs_pct", + ggtheme = theme_bw()) } # plot survival after diagnosis per sex sma_plot_surv_dx_sex <- function() { - plot(survfit(surv_dx ~ sex, data = secmal), mark.time = TRUE, - xscale = 365.25, xlab = "Years", ylab = "Survival", - lty = 2:3) - title("Kaplan-Meier estimate for\nsecMalASCT study", - "Survival after diagnosis") - legend(100, .9, c("Female", "Male"), lty = 2:3) + 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, + surv.median.line = "hv", + risk.table = "abs_pct", + ggtheme = theme_bw(), + pval = TRUE) } # plot survival after transplantation sma_plot_surv_asct <- function() { - plot(survfit(surv_asct ~ 1), mark.time = TRUE, xscale = 365.25, - xlab = "Years", ylab = "Survival") - title("Kaplan-Meier estimate for\nsecMalASCT study", - "Survival after transplantation") + ggsurvplot(survfit(surv_asct ~ 1), data = secmal, xscale = "d_y", + title = "Survival after transplantation", + break.time.by = 5 * 365.25, + surv.median.line = "hv", + risk.table = "abs_pct", + ggtheme = theme_bw()) } # plot survival after transplantation per sex sma_plot_surv_asct_sex <- function() { - plot(survfit(surv_asct ~ sex, data = secmal), mark.time = TRUE, - xscale = 365.25, xlab = "Years", ylab = "Survival", - lty = 2:3) - title("Kaplan-Meier estimate for\nsecMalASCT study", - "Survival after transplantation") - legend(100, .9, c("Female", "Male"), lty = 2:3) + 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, + surv.median.line = "hv", + risk.table = "abs_pct", + ggtheme = theme_bw(), + pval = TRUE) } # diff --git a/utils.R b/utils.R index 2972992..9ca0719 100644 --- a/utils.R +++ b/utils.R @@ -17,7 +17,14 @@ sma_plot_file <- function(fname, ftype, fun) { # Open file for writing ftype(filename = fname, width = 3000, height = 3000, res = 300) - fun() + # + # Write plot into variable, then printing it manually. This is + # needed to save plots from package "survminer" at the moment. + # + # See: https://github.com/kassambara/survminer/issues/152 + # + p <- fun() + print(p) # hide "null device 1" in garbage garbage <- dev.off()