plot.mlm_jn: Plot a Johnson-Neyman interval from a multilevel model

View source: R/mlm_jn.R

plot.mlm_jnR Documentation

Plot a Johnson-Neyman interval from a multilevel model

Description

Creates a ggplot2 figure showing the simple slope of pred across the full range of modx, with shading indicating regions of significance. A vertical dashed line marks each Johnson-Neyman boundary.

Usage

## S3 method for class 'mlm_jn'
plot(
  x,
  x_label = NULL,
  y_label = NULL,
  sig_color = "#2166AC",
  nonsig_color = "#D6604D",
  ...
)

Arguments

x

An mlm_jn object from mlm_jn().

x_label

Label for the x-axis. Defaults to the moderator name.

y_label

Label for the y-axis. Defaults to "Simple slope of pred".

sig_color

Fill colour for the significant region. Default "#2166AC".

nonsig_color

Fill colour for the non-significant region. Default "#D6604D".

...

Ignored.

Value

A ggplot object.

Examples

set.seed(1)
dat <- data.frame(
  y   = rnorm(200), x = rnorm(200),
  m   = rep(rnorm(20), each = 10),
  grp = factor(rep(1:20, each = 10))
)
dat$y <- dat$y + dat$x * dat$m
mod <- lme4::lmer(y ~ x * m + (1 | grp), data = dat,
                  control = lme4::lmerControl(optimizer = "bobyqa"))
jn <- mlm_jn(mod, pred = "x", modx = "m")
plot(jn)


mlmoderator documentation built on April 4, 2026, 1:07 a.m.