nar: Add a numbers at risk table to a Kaplan-Meier plot

Description Usage Arguments Value Author(s) Examples

Description

Creates a numbers at risk table based on a ggplot object created by the plot_survfit function. It will add a table in the lower part of the plot, with numbers where the X axis tick marks are situated.

Usage

1
2
3
nar(g, size = NA, x_offset = 0.02, y_offset = 0.05,
  forced_height = NULL, flip = FALSE, separator = TRUE,
  sep_lwd = 0.2, sep_color = "grey70")

Arguments

g

a ggplot object to which a numbers at risk table should be added.

size

a numeric value indicating the font size of the NAR table

x_offset

a constant indicating how much padding should be placed to the left of the NAR table (a multiple of the plot size in the X dimension)

y_offset

a constant indicating how much each line in the NAR table should be offset (as a multiple of both the plotting space size and the row number)

forced_height

a constant that, if provided, will force the NAR table to be of a certain height. This represents a multiple of the plot size in the Y dimension. This overrides the y_offset setting. Useful when you wish to plot multiple plots along side each other where the number of strata differs, as this setting will ensure that the sizes of the NAR tables are constant.

flip

a logical scalar indicating wheter the order in rows of the NAR table should be flipped or not.

separator

a logical scalar indicating whether a line that separates the plot from the NAR table should be put in place

sep_lwd

what width should that line have?

sep_color

which color should we use for that line?

Value

Returns a ggplot object

Author(s)

Daniel Lindholm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(survsup); library(ggplot2); library(dplyr); library(survival)

retinopathy %>%
    survfit(Surv(futime, status) ~ trt, data = .) %>%
   plot_survfit() %>%
	   nar()

# Without table flip:
flchain %>%
    survfit(Surv(futime, death) ~ sex, data = .) %>%
   plot_survfit(cuminc = FALSE) %>%
   nar()

# With table flip:
flchain %>%
    survfit(Surv(futime, death) ~ sex, data = .) %>%
   plot_survfit(cuminc = FALSE) %>%
   nar(flip = TRUE)

survsup documentation built on May 7, 2019, 9:02 a.m.