README.md

Install

You can install the latest development version from github:

devtools::install_github("jbirstler/survivalFigs")

Basic Usage

The main user functions in this package are:

topFigureEx1 <- makeKMFig(
  formula = survival::Surv(stime, scens) ~ treatment,
  data = mice
)
bottomChartEx1 <- makeNumRiskFig(
  formula = survival::Surv(stime, scens) ~ treatment,
  data = mice
)
combineSurvFigs(topFigureEx1, bottomChartEx1)

timepts, colors, and ribbon

Custom timepts along the x-axis and colors for KM curves or chart text can be specified in arguments. The confidence band ribbon can be removed.

topFigureEx2 <- makeKMFig(
  formula = survival::Surv(stime, scens) ~ treatment,
  data = mice, ribbon = FALSE,
  colors = c("black", RColorBrewer::brewer.pal(3, "Set1")),
  timepts = seq(from = 0, to = max(mice$stime), by = 15)
)
bottomChartEx2 <- makeNumRiskFig(
  formula = survival::Surv(stime, scens) ~ treatment,
  data = mice,
  colors = c("black", RColorBrewer::brewer.pal(3, "Set1")),
  timepts = seq(from = 0, to = max(mice$stime), by = 15)
)
combineSurvFigs(topFigureEx2, bottomChartEx2)

Modifying component figures

makeKMFig() and makeNumRiskFig() both return completely separate ggplot2 figures which can be modified like any other ggplot2 figure. The result can be a stand-alone figure or combined with the other component with combineSurvFigs().

library(ggplot2)
makeKMFig(formula = survival::Surv(stime, scens) ~ treatment,
          data = mice) +
  labs(x = "Survival time (days)") +
  theme(legend.position = c(0.1, 0.2),
        legend.background = element_rect(color = "black"),
        panel.grid.major.y = element_line(color = "#DDDDDD"),
        panel.grid.minor.y = element_line(color = "#EEEEEE"))



jbirstler/survivalFigs documentation built on Jan. 18, 2021, 6:28 p.m.