# NOT RUN {
data(efc)
efc$c172code <- sjmisc::to_factor(efc$c172code)
fit <- lm(barthtot ~ c12hour + c161sex + c172code * neg_c_7, data = efc)
gginteraction(fit)
# this would give the same results
ggpredict(fit, terms = c("neg_c_7", "c172code"))
library(ggplot2)
ggplot(gginteraction(fit), aes(x, predicted, colour = group)) +
geom_line()
dat <- gginteraction(fit)
ggplot(dat, aes(x, predicted, colour = group)) +
geom_line() +
labs(
colour = get_legend_title(dat),
x = get_x_title(dat),
y = get_y_title(dat),
title = get_title(dat)
) +
scale_color_manual(
values = c("red", "green", "blue"),
labels = get_legend_labels(dat)
)
# use continuous term on x-axis, but use values mean +/- sd as groups
dat <- gginteraction(fit, mdrt.values = "meansd", swap.pred = TRUE)
ggplot(dat, aes(x, predicted, colour = group)) + geom_line()
# }
Run the code above in your browser using DataLab