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.
This commit is contained in:
parent
b5634b7f8f
commit
12ffcd4e38
@ -4,3 +4,4 @@ secMalASCT statistical analysis
|
||||
R packages used
|
||||
---------------
|
||||
* tidyverse
|
||||
* survminer
|
||||
|
||||
37
survival.R
37
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,34 @@ 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)
|
||||
}
|
||||
|
||||
# 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,
|
||||
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)
|
||||
}
|
||||
|
||||
# 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,
|
||||
pval = TRUE)
|
||||
}
|
||||
|
||||
#
|
||||
|
||||
9
utils.R
9
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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user