#' genesurv function
#'
#' Draws survminer survival plot for high and low gene populations
#'
#' @param pat2 data frame generated by rnasubset function
#' @param gene character(1) gene of interest
#'
#' @import data.table
#' @import survival
#' @import survminer
#' @import ggplot2
#'
#' @return survminer styled Survival plot
#'
#' @examples
#' data(skcm)
#' gene <- "SOX10"
#' sox10 <- rnasubset(pat, rna, gene, 10)
#' genesurv(sox10, gene)
#'
#' @export
#'
genesurv <- function(pat2, gene) {
setkey(pat2, gene2)
pat2.surv <- with(pat2[!("middle")], Surv(TCGA_year, vitalstatus) ~ gene2)
survplot <- do.call(survfit, args=list(formula = pat2.surv))
half <- summary(survplot)$table[,"median"]
n <- summary(survplot)$table[,"records"]
res <- ggsurvplot(survplot,
data = pat2[!("middle")],
pval=T,
pval.coord = c(1,0.1),
conf.int = T,
risk.table = T,
risk.table.y.text = F,
break.time.by = 1,
palette = c("#1a1a1a", "#d7191c"),
legend = c(0.8, 0.8),
legend.title = "Gene level",
legend.labs = c(sprintf("%s %s, n=%s\n Median OS %s years\n", gene, levels(pat2$gene2)[1], n[1], round(half[1],2)) ,
sprintf("%s %s, n=%s\n Median OS %s years\n", gene, levels(pat2$gene2)[2], n[2], round(half[2],2))),
xlab = "Time Since Biopsy (Years)")
res$table <- res$table + theme(axis.line = element_blank())
print(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.