Plot the residuals generated by the get_schoenfeld function.
This function creates a visual representation of Schoenfeld residuals from a
Cox proportional hazards model.
It allows for customization of the plot, including the addition of horizontal
and smoothed lines, and styling of points and plot elements.
plot_schoenfeld(
residuals,
hline = TRUE,
sline = TRUE,
sline_se = TRUE,
hline_col = "#F8766D",
hline_size = 1,
hline_alpha = 1,
hline_yintercept = 0,
hline_lty = "dashed",
sline_col = "#00BFC4",
sline_size = 1,
sline_alpha = 0.2,
sline_lty = "dashed",
point_col = "black",
point_size = 1,
point_shape = 19,
point_alpha = 1,
plot_theme = ggplot2::theme_bw()
)A ggplot object representing the plot of Schoenfeld residuals.
A data frame containing the Schoenfeld residuals, typically
with columns time, residual, transform, and variable.
Logical. If TRUE, a horizontal line is added to the plot.
Default is TRUE.
Logical. If TRUE, a smooth line is added to the plot.
Default is TRUE.
Logical. If TRUE, confidence intervals are displayed around
the smooth line. Default is TRUE.
Color of the horizontal line. Default is "#F8766D" (red).
Line width of the horizontal line. Default is 1.
Transparency of the horizontal line. Default is 1.
Y-intercept for the horizontal line. Default is 0.
Line type for the horizontal line. Default is "dashed".
Color of the smooth line. Default is "#00BFC4" (blue).
Line width of the smooth line. Default is 1.
Transparency of the smooth line. Default is 0.2.
Line type for the smooth line. Default is "dashed".
Color of the points representing residuals. Default is
"black".
Size of the points representing residuals. Default is 1.
Shape of the points representing residuals. Default is
19.
Transparency of the points representing residuals. Default
is 1.
A ggplot2 theme for the plot. Default is
ggplot2::theme_bw().
library(survival)
test_fit <- survival::coxph(survival::Surv(time, status) ~ sex, data = lung)
test_fit_zph <- survival::cox.zph(test_fit)
plot_schoenfeld(get_schoenfeld(test_fit_zph))
Run the code above in your browser using DataLab