View source: R/stat_km_ticks.R
stat_km_ticks | R Documentation |
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.
stat_km_ticks(
mapping = NULL,
data = NULL,
geom = "km_ticks",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...
)
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 for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to
|
A data.frame
with columns:
time
: time
in data
.
survival
: survival estimate at time
.
n.risk
: number of patients at risk.
n.censor
: number of patients censored.
n.event
: number of patients with event.
Logical status
is not supported.
Michael Sachs (in ggkm
), Samer Mouksassi (in ggquickeda
).
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.