You can install the latest development version from github:
devtools::install_github("jbirstler/survivalFigs")
The main user functions in this package are:
makeKMFig()
which makes a Kaplan-Meier ggplot2 figuremakeNumRiskFig()
which makes a number-at-risk chart as a ggplot2
figurecombineSurvFigs()
which aligns and combines the two, although they
can be used separatelytopFigureEx1 <- makeKMFig(
formula = survival::Surv(stime, scens) ~ treatment,
data = mice
)
bottomChartEx1 <- makeNumRiskFig(
formula = survival::Surv(stime, scens) ~ treatment,
data = mice
)
combineSurvFigs(topFigureEx1, bottomChartEx1)
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)
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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.