ggfitStrata: Graph fitted stratified survival curves from Cox Proportional...

Description Usage Arguments Details See Also Examples

View source: R/ggfitStrata.R

Description

This function largely improves plot.survfit. It plots the curves using ggplot2 rather than base R graphics. One major advantage is the ability to split the survival curves into multiple plots and arrange them in a grid. This makes it easier to examine many strata at once. Otherwise they can be very bunched up.

Note: the strata legend labels need to be changed manually (see revalue) in the survfit object with the strata component.

Usage

1
2
3
4
5
6
7
8
9
ggfitStrata(
  obj,
  byStrata = FALSE,
  xlab = "",
  ylab = "",
  title = "",
  lcolour = "#2C7FB8",
  rcolour = "#2C7FB8"
)

Arguments

obj

a survfit object.

byStrata

logical, whether or not you want to include all of the stratified survival curves on one plot or separate them into a grid arranged plot.

xlab

a label for the plot's x-axis

ylab

a label of the plot's y-axis

title

plot title.

lcolour

line color. Currently only works if byStrata = TRUE. The default it lcolour = "#2C7FB8" (a bluish hexadecimal colour)

rcolour

confidence bounds ribbon color. Either a single color or a vector of colours. The default it lcolour = "#2C7FB8" (a bluish hexadecimal colour)

Details

ggfitStrata graphs fitted survival curves created with survfit using ggplot2.

See Also

survfit, ggplot2 and strata

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Load packages
library(survival)
library(simPH)

# Subset data
bladder1 <- bladder[bladder$enum < 5, ]

# Estimate coxph model (note that this model is for code illustration only)
M1 <- coxph(Surv(stop, event) ~ (rx + size + number) + strata(enum) +
                cluster(id), bladder1)

# Find predicted values
M1Fit <- survfit(M1)

# Plot strata in a grid
ggfitStrata(M1Fit, byStrata = TRUE)

# Plot all in one
ggfitStrata(M1Fit, byStrata = FALSE)

simPH documentation built on Jan. 13, 2021, 6:52 a.m.