I used sjPlot to plot a significant three-way interaction from a glm model using a Gamma distribution. The DV is continuous, two of the IVs are continuous, and one is categorical. I'd love to have the plot be faceted by the categorical variable, with lines on each that show mean +/- 1 sd (shown below). I got a very nice facet-wrapped plot and am able to modify the axis limits, titles, etc. However, I don't know how to change certain aesthetics, such as removing the axis lines/grids, making the background color white, changing the color of the bands at the top of the facets, etc. I can do this in ggplot, but I'd really love to use the specific predicted values from the model because it contains covariates in addition to the IV, DV, and moderators.
Here's an example using the iris dataset:
iris.glm<-glm(Sepal.Length ~ Sepal.Width*Petal.Width*Species + Petal.Length,
family = Gamma(link="inverse"), data=iris)
summary(iris.glm)
plot_model(iris.glm, type="int", mdrt.values="meansd", axis.lim=c(4,10),
title="", axis.title=c("Sepal Width", "Sepal Length"),
legend.title="Petal Width", colors=c("#66c2a5","#fc8d62", "#8da0cb"))
However, I'd like to do more refining of the aesthetics. When I try to recreate this plot in ggplot, I'm doing a terrible job! In particular I don't know how to essentially convert the continuous moderator to a three-level category (-1 SD, Mean, 1 SD). Do I need to create a separate data frame with predicted values from the model and create a plot from that? If so, could someone help with that? Apologies in advance, still a novice with ggplot.
iris %>%
ggplot(aes(x=Sepal.Width, y=Sepal.Length, color=Petal.Width, group=Petal.Width)) +
facet_grid(~Species) +
stat_smooth(method = "glm", se=T) +
xlab("Sepal Width") +
ylab("Sepal Length") +
coord_cartesian(xlim =c(2, 4.5), ylim = c(4, 10))