stat_km_ticks {ggplot2.utils} | R Documentation |
Adds Tick Marks to a Kaplan-Meier Estimate of Survival Statistic
Description
This stat
is for computing the location of the tick marks for the
Kaplan-Meier survival estimate for right-censored data.
It requires the aesthetic mapping time
for the
observation times and status
which indicates the event status,
either 0 for alive and 1 for dead, or 1 for alive and 2 for dead.
Usage
stat_km_ticks(
mapping = NULL,
data = NULL,
geom = "km_ticks",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
Value
A data.frame
with columns:
-
time
:time
indata
. -
survival
: survival estimate attime
. -
n.risk
: number of patients at risk. -
n.censor
: number of patients censored. -
n.event
: number of patients with event.
Note
Logical status
is not supported.
Author(s)
Michael Sachs (in ggkm
), Samer Mouksassi (in ggquickeda
).
Examples
library(ggplot2)
sex <- rbinom(250, 1, .5)
df <- data.frame(
time = exp(rnorm(250, mean = sex)),
status = rbinom(250, 1, .75),
sex = sex
)
ggplot(df, aes(time = time, status = status, color = factor(sex))) +
stat_km() +
stat_km_ticks()