addNrisk: Add number-at-risk annotations to a plot

View source: R/addNrisk.R

nriskR Documentation

Add number-at-risk annotations to a plot

Description

Add number-at-risk (NAR) annotations to an existing survival plot, underneath the X-axis. 2009-02-20 Aron Charles Eklund http://www.cbs.dtu.dk

Usage

nrisk(x, times = pretty(x$time))

addNrisk(
  x,
  at = axTicks(1),
  line = 4,
  hadj = 0.5,
  title = "Number at risk",
  title.adj = 0,
  labels,
  hoff = 5,
  col = 1,
  ...
)

Arguments

x

A list as returned by survfit

at

Time points at which the NAR values are calculated and placed.

line

Number of lines into the margin to start displaying the NAR.

hadj

izontal adjustment for the NAR values

title

Optional title above the NAR.

title.adj

Text adjustment for the title

labels

Labels for each stratum.

hoff

Horizontal offset for the labels

col

Color for each stratum.

...

an axis gap.axis, cex.axis, col.axis and font.axis

Value

data.frame

Examples




require("survival")

s <- Surv(colon$time / 365, colon$status)

## Need to increase margins a bit
par(mar = c(10, 6, 2, 1),mfrow = c(1,2))

## no stratification
fit1 <- survfit(s ~ 1)
plot(fit1)
addNrisk(fit1)

## with stratification
at <- c(0, 2, 4)
lty <- 1:3
xlim <- c(0, 6)
fit2 <- survfit(s ~ rx, data = colon)
plot(fit2,
     xlab = 'Time (years)',
     ylab = 'Survival',
     xaxt = "n",
     xlim=xlim,
     lty = lty)

addNrisk(fit2, at)
axis(1, at = at, gap.axis = 1 / 4)
legend(
  'bottomleft',
  legend = names(fit2$strata),
  lty = lty,
  bty = 'n'
)
Hmisc::minor.tick(nx = 4, tick.ratio = 1 / 2)


stp4/stp25plot documentation built on March 29, 2025, 4:26 p.m.