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