Numbers-at-risk table for PHS percentile-stratified groups
Source:R/phs_risk_table.R
phs_risk_table.RdBuilds a ggplot2 numbers-at-risk strip intended for combining with a
phs_abs_risk() or phs_km_curve() plot using patchwork. Accepts the
same data and interval arguments as those functions and computes the
survival data internally.
Arguments
- data
data.frame with columns specified by
phs,time, andevent- phs
string; column name of the continuous PHS values
- time
string; column name of the time-to-event variable
- event
string; column name of the event indicator (0 = censored, 1 = event of interest)
- competing_event
string or NULL; column name of the competing event indicator. Required when
method = "aalen_johansen".- intervals
list of
c(lo, hi)pairs defining percentile bands. Should match theintervalsused in the accompanyingphs_abs_risk()orphs_km_curve()call.- ref_data
optional data.frame used as the reference population for computing percentile cutpoints.
- method
string;
"km"(default) or"aalen_johansen". Should match the method used in the accompanying curve function.- palette
string; color palette name. Should match the palette used in the accompanying curve plot (default
"hazrd").- time_points
numeric vector or NULL; time values at which to display numbers at risk. For example,
c(50, 60, 70, 80, 90). When NULL (default), values are chosen automatically usingpretty().- ...
additional arguments (reserved for future use).
Value
A ggplot2 object displaying the numbers at risk over time for each
stratum. Combine with the output of phs_abs_risk() or
phs_km_curve() using patchwork, e.g.:
p / phs_risk_table(data) + patchwork::plot_layout(heights = c(3, 1)).
Examples
data(test_data)
p <- phs_abs_risk(test_data)
rt <- phs_risk_table(test_data)
# Specify exact ages for the at-risk columns:
rt <- phs_risk_table(test_data, time_points = c(50, 60, 70, 80))
# Combine with patchwork:
# p / rt + patchwork::plot_layout(heights = c(3, 1))