# NOT RUN {
# Fit the drsurv model
#++++++++++++++++++++++++++++++++++++
require(survival)
lung$sex <- as.factor(lung$sex)
levels(lung$sex) <- c("Male", "Female")
fit <- drsurv(time = lung$time, status = lung$status, factor = lung$sex, ref = "Female")
# Visualise the drsurv model output
#++++++++++++++++++++++++++++++++++++
# Basic survival curves
ggsurv(fit, statistics = "surv")
# Customized survival curves
ggsurv(fit, statistics = "surv",
palette = c("Orange", "purple"),
xlab = "Time (days)", ylab = "Estimated Survival Probability",
theme = "classic",
table = TRUE,
p.value = TRUE,
break.times.by = 200)
# Survival difference curve
ggsurv(fit, statistics = "diff")
# Survival difference curve without the point wise significant different times flag
ggsurv(fit, statistics = "diff", flag = FALSE)
# Customized survival difference curve
ggsurv(fit, statistics = "diff",
palette = c("gray"),
xlab = "Time (days)", ylab = "Estimated Survival Difference",
theme = "classic",
flag = TRUE,
flag.col = c("darkseagreen", "red4"),
break.times.by = 200)
# Survival ratio curve
ggsurv(fit, statistics = "ratio")
# Customized survival ratio curve with further ggplot2 objects
ggsurv(fit, statistics = "ratio") +
ggtitle("Overall survival from lung cancer") +
theme(legend.position="bottom",
legend.background = element_rect(fill="lightblue", linetype="solid")
)
# Displaying all the survival, difference and ratio curves in one graphic
## For better visualisation, user may need to increase the ratio of "Plots" pannel
## in Rstudio working environment.
ggsurv(fit, statistics = "all")
# Customized all in one curves
ggsurv(fit, statistics = "all",
palette = c("Orange", "purple", "dimgray", "dimgray"),
xlab = "Time (days)",
ylab = c("Estimated Survivor Function", "Estimated Survival Difference",
"Estimated Survival Ratio"),
theme = "light",
table = TRUE, ## table will be only shown for the survival plot.
p.value = TRUE, ## p.value will be only displayed for the survival plot.
flag = TRUE,
flag.col = c("limegreen", "darkred"),
break.times.by = 150)
# personalized all in one curves
survp <- ggsurv(fit, statistics = "surv",
p.value = TRUE,
table = TRUE)
diffp <- ggsurv(fit, statistics = "diff")
ratiop <- ggsurv(fit, statistics = "ratio")
## changing the labels
ggpubr::ggarrange(survp,
ggpubr::ggarrange(diffp, ratiop, ncol = 2, labels = c("(ii)", "(iii)")),
nrow = 2,
labels = "(i)",
heights = c(1.3,1) # first row's height is 1.3 times bigger than 2nd row's height.
)
## changing the alignment and save it locally
#png("all_in_one.png", height = 1000, res=100)
#ggpubr::ggarrange(ratiop, diffp, survp,
# nrow = 3,
# labels = c("(i)","(ii)", "(iii)"),
# heights = c(1,1,1.5) # 1st and 2nd rows' heights are equal while
# # the 3rd row's height is 1.5 times bigger than the first #two rows.
#)
#dev.off()
## get the directory where the plot is saved
getwd()
### See ?ggpubr::ggarrange for more customizations.
# }
Run the code above in your browser using DataLab