rms modelThe ggrmsMD function processes the output from models fitted using the rms package and produces one or more ggplot2 objects visualising restricted cubic splines (RCS).
The function detects RCS terms in the model and plots them all, with a suitable y-axis selected based on the model type. This outputs a list of plots, or a multi-panel figure using the combined argument.
As outputs are ggplot objects they can easily be further customised by the user.
ggrmsMD(
modelfit,
data,
noeffline = TRUE,
shade_inferior = "none",
combined = TRUE,
ylab = NULL,
xlabs = NULL,
titles = NULL,
ylim = NULL,
log_y = FALSE,
log_y_breaks = NULL,
xlims = NULL,
log_x_vars = NULL,
log_x_breaks = NULL,
lrm_prob = FALSE,
var = NULL,
np = 400,
...
)A ggplot object (if one variable is plotted), a list of ggplot objects (if multiple variables), or a single combined cowplot plot if combined = TRUE.
A model object from ols, lrm, or cph (from the rms package).
The dataset used to fit the model.
Logical. If TRUE (default), adds a horizontal dashed line at 1 for odds/hazard ratio plots.
Character. Options are "none" (default), "higher", or "lower". Applies red/green shading above or below 1 on the y-axis to indicate worse/better outcomes.
Logical. If TRUE, returns a single multi-panel plot using cowplot::plot_grid().
Optional character. Override the default y-axis label.
A named list of x-axis labels for each variable. E.g., list(age = "Age (years)", bmi = "BMI (kg/m²")).
A named list of plot titles for each variable.
Numeric vector (length 2). y-axis limits applied to all plots. E.g., c(0.5, 2).
Logical. If TRUE, y-axis is log10-transformed.
Optional numeric vector specifying y-axis tick marks when log_y = TRUE. E.g., c(0.25, 0.5, 1, 2, 4).
A named list of x-axis limits per variable. E.g., list(age = c(20, 80)).
Character vector. Names of variables for which x-axis should be log10-transformed.
A named list specifying x-axis tick marks for variables with log10-transformed x-axis.
Logical. If TRUE and model is lrm, plots predicted probabilities instead of odds ratios.
Character vector. Optional. Variables to plot. If NULL (default), all RCS variables in the model will be plotted.
Integer. Number of points used to predict spline curves. Default is 400. Consider increasing when using log-transformed x-axes.
Additional arguments passed to cowplot::plot_grid() when combined = TRUE.
# For details examples and plots please see the provided vignettes
Run the code above in your browser using DataLab