View source: R/pcoxtimeplots.R
| plot.pcoxsurvfit | R Documentation |
Plot estimated survival and cumulative hazard curves for pcoxtime model.
## S3 method for class 'pcoxsurvfit'
plot(
x,
...,
type = c("surv", "cumhaz"),
lsize = 0.3,
lcol = "black",
compare = FALSE
)
x |
a |
... |
for future implementations |
type |
type of curve to generate. Either |
lsize |
line size for the curves. |
lcol |
colour for the curves. |
compare |
logical. Whether to return plot with labels to add additional |
Depending on the specification in pcoxsurvfit.pcoxtime, this function plots either average or individual survival or cumulative hazard curves. The plot is a ggplot object, hence can be be customized further, see example below.
a ggplot object.
library(ggplot2)
data(heart, package="survival")
lam <- 0.02
alp <- 1
pfit <- pcoxtime(Surv(start, stop, event) ~ age + year + surgery + transplant
, data = heart
, lambda = lam
, alpha = alp
)
# Plot survival curves
psurv <- pcoxsurvfit(pfit)
plot(psurv)
# Baseline survival curve
bsurv <- pcoxbasehaz(pfit, centered = FALSE)
plot(bsurv)
# Compare overall and baseline cumulative hazard
p1 <- plot(psurv, type = "cumhaz", compare = TRUE)
df2 <- data.frame(time = bsurv$time, cumhaz = bsurv$hazard)
p2 <- (p1
+ geom_step(data = df2, aes(x = time, y = cumhaz, group = 1, col = "baseline"))
+ scale_colour_manual(name = "C. hazard"
, values = c("#E41A1C", "#000000")
, labels = c("baseline", "overall")
)
)
print(p2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.