rcs_plot {clinpubr} | R Documentation |
Plot restricted cubic spline
Description
Plot restricted cubic spline based on package rms
. Support both logistic and cox model.
Usage
rcs_plot(
data,
x,
y,
time = NULL,
covars = NULL,
knot = 4,
add_hist = TRUE,
ref = "x_median",
ref_digits = 3,
group_by_ref = TRUE,
group_title = NULL,
group_labels = NULL,
group_colors = NULL,
breaks = 20,
rcs_color = "#e23e57",
print_p_ph = TRUE,
trans = "identity",
save_plot = FALSE,
filename = NULL,
y_lim = NULL,
hist_max = NULL,
xlim = NULL,
height = 6,
width = 6,
return_details = FALSE
)
Arguments
data |
A data frame. |
x |
A character string of the predictor variable. |
y |
A character string of the outcome variable. |
time |
A character string of the time variable. If |
covars |
A character vector of covariate names. |
knot |
The number of knots. If |
add_hist |
A logical value. If |
ref |
The reference value for the plot. Could be |
ref_digits |
The number of digits for the reference value. |
group_by_ref |
A logical value. If |
group_title |
A character string of the title for the group. Ignored if |
group_labels |
A character vector of the labels for the group. If |
group_colors |
A character vector of colors for the plot. If |
breaks |
The number of breaks for the histogram. |
rcs_color |
The color for the restricted cubic spline. |
print_p_ph |
A logical value. If |
trans |
The transformation for the y axis in the plot.
Passed to |
save_plot |
A logical value indicating whether to save the plot. |
filename |
A character string specifying the filename for the plot. If |
y_lim |
The range of effect value of the plot. If |
hist_max |
The maximum value for the histogram. If |
xlim |
The x-axis limits for the plot. If |
height |
The height of the saved plot. |
width |
The width of the saved plot. |
return_details |
A logical value indicating whether to return the details of the plot. |
Value
A ggplot
object, or a list containing the ggplot
object and other details if return_details
is TRUE
.
Examples
data(cancer, package = "survival")
# coxph model with time assigned
rcs_plot(cancer, x = "age", y = "status", time = "time", covars = "ph.karno", save_plot = FALSE)
# logistic model with time not assigned
cancer$dead <- cancer$status == 2
rcs_plot(cancer, x = "age", y = "dead", covars = "ph.karno", save_plot = FALSE)