Diego NabaJo
Diego NabaJo

Reputation: 1

Interaction plots: How to set prediction ranges according to the observed-data range of each category in sjPlot?

Using sjPlot, I would like to have the prediction lines (and CIs) limited to the range of x1 values with observed data for that category (x2's factor levels, or numerical chosen levels).

This is the code for an example of the standard plot generated by sjPlot: we can see the lines of different colors share the whole range of x1 observed data. I would like the lines of each level (and color) to span only to the range of x values where there are data points for that specific level.

library(sjPlot)
library(sjmisc)
library(ggplot2)

mtcars.df <- mtcars
fit <- lm(mpg ~ hp * disp, data = mtcars.df)
plot_model(fit, type = "pred", terms = c("hp", "disp"), show.data = T)

Interaction plot

The following plot is an example of what I would like:
the line for level "FS" goes from 0 to 50 in the X axis, while the other two levels reach 70 in the X axis. In this case, a categorical variable "Sitio".
Interaction plot 2

Upvotes: 0

Views: 11

Answers (0)

Related Questions