% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom_prodlim.R
\name{geom_prodlim}
\alias{geom_prodlim}
\title{Product-limit geoms for survival and competing risks curves}
\usage{
geom_prodlim(
  mapping = NULL,
  data = NULL,
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  type = "risk",
  cause = NULL,
  conf_int = TRUE,
  conf_int_alpha = 0.2,
  percent = TRUE,
  timeconverter = NULL,
  times = NULL,
  cens.code = "0",
  ...
)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by [ggplot2::aes()].}

\item{data}{Data frame.}

\item{position}{Position adjustment.}

\item{na.rm}{If `FALSE`, missing values are removed with a warning.}

\item{show.legend}{Logical. Should this layer be included in the legends?}

\item{inherit.aes}{If `FALSE`, overrides the default aesthetics.}

\item{type}{Passed to [prodlim::prodlim()], usually `"risk"` or `"surv"`.}

\item{cause}{Cause(s) for competing risks. Can be a vector of causes or the
string `"stacked"`.}

\item{conf_int}{Logical. Draw confidence intervals.}

\item{conf_int_alpha}{Alpha level for confidence shadows.}

\item{percent}{Logical. Passed to [prodlim::summary.prodlim()].}

\item{timeconverter}{Optional time conversion string.}

\item{times}{Optional evaluation times passed to
[prodlim::summary.prodlim()].}

\item{cens.code}{Censoring code passed to [prodlim::Hist()].}

\item{...}{Further arguments passed to [ggplot2::layer()].}
}
\description{
Draw Kaplan-Meier or Aalen-Johansen curves with optional confidence bands.
For competing risks with multiple causes, the default display shows one curve
per cause. When `cause = "stacked"`, causes are drawn as stacked filled
rectangles instead of step curves with confidence shadows.
}
\details{
When multiple causes are specified, `fill`/`colour` aesthetics are ignored
and replaced by a cause-based mapping so that all causes are shown in a
single legend. When `cause = "stacked"`, causes are stacked on top of each
other and confidence shadows are not drawn.
}
\examples{
library(riskRegression)
library(data.table)
library(ggplot2)
data(Melanoma)
# Kaplan-Meier
ggplot(data = Melanoma,aes(x = time, event = 1*(status != 0)))+
       geom_prodlim(type = "surv")
# stratified Kaplan-Meier inherited aes
ggplot(data = Melanoma,aes(x = time, event = 1*(status != 0),fill = sex,color = sex))+
       geom_prodlim(type = "surv")
# stratified Kaplan-Meier geom aes
ggplot(data = Melanoma,aes(x = time, event = 1*(status != 0)))+
       geom_prodlim(aes(fill = sex,color = sex),type = "surv")
# facet
ggplot(data = Melanoma,aes(x = time, event = 1*(status != 0)))+
       geom_prodlim(type = "surv")+facet_grid(~sex)
# stratified and facet
ggplot(data = Melanoma,aes(x = time, event = 1*(status != 0),fill = epicel,color = epicel))+
       geom_prodlim(type = "surv")+facet_grid(~sex)

# Aalen-Johansen
ggplot(data = Melanoma,aes(x = time, event = status))+
       geom_prodlim(type = "surv",cause = 1:2)
# stratified Aalen-Johansen inherited aes
ggplot(data = Melanoma,aes(x = time, event = status,fill = sex,color = sex))+
       geom_prodlim(type = "surv")
# stratified Aalen-Johansen geom aes
ggplot(data = Melanoma,aes(x = time, event = status))+
       geom_prodlim(aes(fill = sex,color = sex),type = "surv")
# facet
ggplot(data = Melanoma,aes(x = time, event = status))+
       geom_prodlim(type = "surv")+facet_grid(~sex)
# stratified and facet
ggplot(data = Melanoma,aes(x = time, event = status,fill = epicel,color = epicel))+
       geom_prodlim(type = "surv")+facet_grid(~sex)
# stacked
ggplot(data = Melanoma,aes(x = time, event = status))+
       geom_prodlim(cause = "stacked")+facet_grid(~sex)
# stacked with cens.code option
ggplot(data = Melanoma,aes(x = time, event = event))+
       geom_prodlim(cens.code="censored",cause = "stacked")+facet_grid(~sex)
}
