km.plot: Kaplan-Meier Survival Plot

Description Usage Arguments Value Author(s) Examples

Description

This function generates Kaplan-Meier survival curves.

Usage

1
km_plot(fit, type, xlim_major, xlim_minor, ylim_major, ylim_minor, grid, col_grid_major, col_grid_minor, lwd_grid_major, lwd_grid_minor, conf_int, mark_time, col, lty, lwd, plot_title, plot_title_size, plot_subtitle, plot_subtitle_size, x_axis_label, y_axis_label, axis_label_size, extra_left_margin, font_family, print_risk_table, print_group_lines, print_group_names, risk_table_title, group_names, group_order, legend, legend_x_loc, legend_y_loc)

Arguments

fit

Fitted model object from survfit. Required.

type

Kaplan-Meier plot ("km") or complement ("1-km"). Optional; defaults to "km".

xlim_major

Vector of x-axis locations for labels and major gridlines. Optional.

xlim_minor

Vector of x-axis locations for minor gridlines. Optional.

ylim_major

Vector of y-axis locations for labels and major gridlines. Optional.

ylim_minor

Vector of y-axis locations for minor gridlines. Optional.

grid

Plot gridlines? Optional logical; defaults to TRUE.

col_grid_major

Color of major gridlines. Optional.

col_grid_minor

Color of minor gridlines. Optional.

lwd_grid_major

Line width of major gridlines. Optional.

lwd_grid_minor

Line width of minor gridlines. Optional.

conf_int

Plot confidence intervals? Optional logical; defaults to FALSE.

mark_time

Plot censoring tick marks? Optional logical; defaults to FALSE.

col

Vector of colors for plotted curves. Optional; defaults to ordered rainbow colors.

lty

Vector of line types for plotted curves. Optional; defaults to all solid.

lwd

Vector of line widths for plotted curves. Optional; defaults to 1.

plot_title

Main plot title. Optional.

plot_title_size

Text size for plot title. Optional.

plot_subtitle

Subtitle for plot. Optional.

plot_subtitle_size

Text size for plot subtitle. Optional.

x_axis_label

Label for the x-axis. Optional; defaults to "Time".

y_axis_label

Label for the y-axis. Optional; defaults to "Probability".

axis_label_size

Text size for axis labels. Optional.

extra_left_margin

Increase numeric value for added left margin padding to accomodate long labels. Optional.

font_family

Choice of "sans", "serif", "mono", or a specified font set up to work on the user's system. Optional; defaults to "serif".

print_risk_table

Print risk table beneath plot? Optional logical; defaults to TRUE.

print_group_lines

Print legend lines next to risk table? Optional logical; defaults to TRUE.

print_group_names

Print group/strata names next to risk table? Optional logical; defaults to TRUE.

risk_table_title

Header for risk table. Optional; defaults to "Total at risk".

group_names

Vector of group names to print in risk table. Optional.

group_order

Numeric vector giving order of groups to be printed in risk table. Optional.

legend

Logical indicator for printing a legend on the plot. Optional; defaults to FALSE since the information is found by default in the risk table.

legend_x_loc

X-axis coordinate or position for the legend location. Optional; defaults to "bottomleft".

legend_y_loc

Y-axis coordinate for the legend location. Optional; defaults to NULL.

Value

Returns a Kaplan-Meier plot with the requested attributes.

Author(s)

Erica Wozniak

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library(survival)

# Set up data as a survival object
# KM plot for time to death
# Censor those who receive a transplant or are indicated by the dataset as censored
pbc_km <- na.omit(pbc[, c("time", "status", "trt")])
pbc_km$status[pbc_km$status == 1] <- 0
pbc_km$status[pbc_km$status == 2] <- 1
pbc_km$SurvObj <- with(pbc_km, 
                       Surv(time  = time, 
                            event = status)
                            )
fit <- survfit(SurvObj ~ trt, 
               data = pbc_km, 
               conf.type = "log-log")
               
# Usage note: if gridlines are extending outside the plot border, run
# "dev.off()" and then run the plotting function again.
               
# Default options only
km_plot(fit = fit)

# Customized pretty plot with some options
km_plot(fit  = fit,
        type = "km",
        col  = c("orange3", "olivedrab"),
        # Add an extra major gridline and risk table column at time 4500
        xlim_major    = c(0, 1000, 2000, 3000, 4000, 4500, 5000),
        plot_title    = "Primary biliary cirrhosis survival",
        plot_subtitle = "By randomized treatment status",
        y_axis_label  = "Survival",
        x_axis_label  = "Time since registration (days)",
        group_names   = c("D-penacillamine", "Placebo"),
        risk_table_title = bquote(italic("Patients at risk:")))

# Customized retro plot with lots of options
km_plot(fit  = fit,
        font_family = "mono",
        type = "1-km",
        col  = c("black", "black"),
        lty  = c(1, 2),
        lwd  = c(2, 2),
        xlim_major = c(0, 500, 1000, 2000, 3000, 3375, 4000, 4500, 5000),
        col_grid_major = "gray80",
        col_grid_minor = "gray92",
        plot_title = bquote(bold("Death following transplant registration")),
        plot_subtitle = "Mayo Clinic 1974-1984",
        plot_title_size = 1,
        y_axis_label = bquote(bold("Cumulative incidence")),
        x_axis_label = bquote(bold("Days")),
        group_names  = c("D-penacillamine", "Placebo"),
        group_order  = c(2, 1),
        risk_table_title  = bquote(bold(underline("RISK TABLE"))),
        extra_left_margin = 5)

emwozniak/kmrskplot documentation built on May 16, 2019, 5:11 a.m.