geom_surv: create a survival curve as a layer ready to be added to a...

Description Usage Arguments Value Examples

View source: R/geom_surv.R

Description

Imports: ggplot2

Usage

1
geom_surv(data, mapping, ticks = "segment", surv_pretty = FALSE, ...)

Arguments

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

mapping

aes object, created with aes(). Provide x (time) and y (status). Optionally you can provide color and linetype to distinguish conditions. For the status: NA will be irgnored, 1 = dropped out, 2 = dead, any other value = alive.

ticks

character, either "segment" or "point". If specified as "point", additional geom_point options can be specified, such as shape

surv_pretty

boolean, if TRUE sets certain options to make the plot more pretty

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

Value

a list of two ggplot2 layer objects (geom_path for the lines and geom_segment for the ticks) that can directly be added to a ggplot2 object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(ggsurvival)
library(ggplot2)

survtest <- data.frame(
  time = sample(seq(30),50,replace = T),
  status = sample(1:2, 50, replace = T),
  condition = sample(c("wt","ko"), 50, replace = T)
)

ggplot() + geom_surv(data=survtest, aes(time, status, color=condition))

NicolasH2/ggsurvival documentation built on Dec. 17, 2021, 5:24 a.m.