0

I'm using the plot_model() function in R to visualize an interaction for an OLS regression. The regression is: model <- lm(dv ~ condition + control1 + control2 + variable1 + condition*variable1, data=data) condition is a 4-level factor variable. variable1 is a continuous variable. control1 is a continuous variable. control2 is a factor variable with 2-levels.

I'm trying to visualize the interaction of this regression, with variable1 on the x-axis, and condition as indicators. However, I'm hoping to visualize it as if variable 1 was a factor variable, i.e., only showing particular points (2, 4, and 6) on the plot, with confidence interval whiskers, instead of a straight line across all continuous values and confindence interval bands around the line. So something that looks like this:

Rather than this:

I've tried multiple things but am having trouble looking for the right solution. Any help will be appreciated! The code I have now that creates the line & band plot is:

plot_model(model, type="pred",terms=c("variable1","condition"), ci.lvl=0.95)
zephryl
  • 14,633
  • 3
  • 11
  • 30
Sgary
  • 1

1 Answers1

1

Specify the points your want in brackets in the terms argument:

library(sjPlot)

model <- lm(hwy ~ year + drv * displ, data = ggplot2::mpg)

plot_model(model, type = "pred", terms = c("drv",  "displ [2, 3, 5]"))

zephryl
  • 14,633
  • 3
  • 11
  • 30