Learn Data & AI Skills | 50% off
Get 50% off unlimited learning

prodlim (version 2025.04.28)

ggprodlim: ggplot2::ggplot support for Kaplan-Meier and Aalen-Johansen estimators

Description

ggplot2::ggplot support for Kaplan-Meier and Aalen-Johansen estimators

Usage

ggprodlim(x, xlim, ylim, y_breaks, x_breaks, position_atrisk, conf_int, ...)

Value

A ggplot2::ggplot object

Arguments

x

object obtained with prodlim.

xlim

Limits for the x-axis.

ylim

Limits for the y-axis.

y_breaks

Breaks for the y-axis.

x_breaks

Breaks for the x-axis.

position_atrisk

Vector of values within xlim. Specifies where numbers at risk should be positioned on the x-axis.

conf_int

Logical. If TRUE pointwise confidence intervals as a shadow.

...

passed on to as.data.table.prodlim. Can be used to specify 'cause', 'newdata', and 'times'.

Author

Thomas A. Gerds <tag@biostat.ku.dk>

Details

Important functionality like facet_grid is not yet supported

See Also

plot.prodlim

Examples

Run this code
library(ggplot2)

# Kaplan-Meier and stratified Kaplan-Meier

set.seed(9)
ds <- SimSurv(27)

km <- prodlim(Hist(time,event)~1,data = ds)
ggprodlim(km)
g <- ggprodlim(km)
g <- g+geom_step(linewidth=1.5)
g + theme(text = element_text(size=20)) + update_geom_defaults("text", list(size=5.5))
km1 <- prodlim(Hist(time,event)~X1,data = ds)
ggprodlim(km1)

ds$group <- factor(sample(1:5,replace=TRUE,size=27),labels=letters[1:5])
km2 <- prodlim(Hist(time,event)~group,data = ds)
ggprodlim(km2,conf_int=FALSE)

# Aalen-Johansen and stratified Aalen-Johansen

set.seed(8)
d <- SimCompRisk(27)
d$X_group <- factor(sample(1:5,replace=TRUE,size=27),labels=letters[1:5])
aj <- prodlim(Hist(time,event)~1,data = d)
ggprodlim(aj)
ggprodlim(aj,cause=1)
ggprodlim(aj,position_atrisk=c(0,5,10))+scale_x_continuous(breaks=c(0,5,10))

ggprodlim(aj)+theme_minimal()+theme(plot.margin=margin(t=0,r=0,b=8,l=0,"line"))

# changing colors
g+ggplot2::scale_fill_manual(values = 1:2)+ggplot2::scale_color_manual(values=1:2)

aj <- prodlim(Hist(time,event)~X1,data = d)
ggprodlim(aj,cause = 1)
d$X1 <- factor(d$X1,levels=c("1","0"),labels=c("1","0"))
aj <- prodlim(Hist(time,event)~X1,data = d)

Run the code above in your browser using DataLab