Advertisement
mud_dauber

Survival Plots h/t @R_souvenirs

May 23rd, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.51 KB | None | 0 0
  1. # How to build informative survival plots
  2. # source: http://r-addict.com/2016/05/23/Informative-Survival-Plots.html
  3.  
  4. # setup
  5. install.packages('survminer')
  6. source("https://bioconductor.org/biocLite.R")
  7. biocLite("RTCGA.clinical") # data for examples
  8.  
  9. Plot the difference in survival times between patients suffering from Ovarian Cancer & Breast Cancer using data collected by The Cancer Genome Atlas Project.
  10.  
  11. library(RTCGA.clinical)
  12. survivalTCGA(BRCA.clinical, OV.clinical, extract.cols = "admin.disease_code") -> BRCAOV.survInfo
  13. library(survival)
  14. fit <- survfit(Surv(times, patient.vital_status) ~ admin.disease_code, data = BRCAOV.survInfo)
  15. library(survminer)
  16. ggsurvplot(fit, risk.table = TRUE)
  17.  
  18. Improved version with parameters:
  19.  
  20. ggsurvplot(
  21.    fit,                     # survfit object with calculated statistics.
  22.    risk.table = TRUE,       # show risk table.
  23.    pval = TRUE,             # show p-value of log-rank test.
  24.    conf.int = TRUE,         # show confidence intervals for
  25.                             # point estimaes of survival curves.
  26.    xlim = c(0,2000),        # present narrower X axis, but not affect
  27.                             # survival estimates.
  28.    break.time.by = 500,     # break X axis in time intervals by 500.
  29.    ggtheme = theme_RTCGA(), # customize plot and risk table with a theme.
  30.  risk.table.y.text.col = T, # colour risk table text annotations.
  31.   risk.table.y.text = FALSE # show bars instead of names in text annotations
  32.                             # in legend of risk table
  33. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement