Generates a standardized line plot for Mixed-Effect Repeated Measures Model (MMRM) analysis. It displays adjusted means (change from baseline) along with either 95% Confidence Intervals (CI) or Standard Errors (SE) over time.

gg_mmrm_lineplot(
  mmrm_df,
  arm,
  visit,
  error_bar = c("ci", "se"),
  dodge_width = 0.15,
  hline = 0,
  legend_pos = c(0.02, 0.02)
)

Arguments

mmrm_df

(data.frame)
A tidy data frame containing the MMRM results. Usually the output of get_mmrm_results().

arm

(string)
The column in mmrm_df that identifies the treatment arms.

visit

(string)
The column in mmrm_df that identifies the visits.

error_bar

(string)
Type of error bars to display. Either "ci" (95% Confidence Interval) or "se" (Standard Error). Default is "ci".

dodge_width

(numeric)
The amount to jitter the x-axis points to prevent overlapping error bars. Default is 0.15.

hline

(numeric or NULL)
The y-intercept for a horizontal reference line. Set to NULL to remove. Default is 0.

legend_pos

(numeric vector or string)
The position of the legend. To place it inside the plot on the bottom left, use c(0.02, 0.02). Can also be standard string positions like "bottom", "right", "none".

Value

A ggplot object.

See also

get_mmrm_results() to get the MMRM results, and tbl_mmrm() for a summary table of the MMRM results.

Examples

if (FALSE) { # identical(Sys.getenv("NOT_CRAN"), "true") && requireNamespace("mmrm", quietly = TRUE)
library(mmrm)
fv_dt <- mmrm::fev_data |>
  dplyr::mutate(
    ARMCD = factor(ARMCD)
  )
# Fit an MMRM model using the FEV data
fit_mmrm <- mmrm::mmrm(
  formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID),
  data = fv_dt
)
mmrm_results <- get_mmrm_results(fit_mmrm, arm = "ARMCD", visit = "AVISIT", conf_level = 0.95)

# Create a plot with SE bars, jittered by 0.2, legend inside bottom-left
my_plot <- gg_mmrm_lineplot(
  mmrm_df = mmrm_results,
  arm = "ARMCD",
  visit = "AVISIT",
  error_bar = "se", # Switch to "ci" for Confidence Intervals
  dodge_width = 0.2, # Jitters the x-axis to prevent overlap
  legend_pos = c(0.02, 0.02)
)

print(my_plot)
}