if (require("dplyr") && require("gridExtra")) {
library(ggeffects)
data(efc)
# fit model
fit <- glm(
tot_sc_e ~ c12hour + e17age + e42dep + neg_c_7,
data = efc,
family = poisson
)
# plot marginal effects for each predictor, each as single plot
p1 <- ggpredict(fit, "c12hour") %>%
plot(show_y_title = FALSE, show_title = FALSE)
p2 <- ggpredict(fit, "e17age") %>%
plot(show_y_title = FALSE, show_title = FALSE)
p3 <- ggpredict(fit, "e42dep") %>%
plot(show_y_title = FALSE, show_title = FALSE)
p4 <- ggpredict(fit, "neg_c_7") %>%
plot(show_y_title = FALSE, show_title = FALSE)
# plot grid
plot_grid(list(p1, p2, p3, p4))
# plot grid
plot_grid(list(p1, p2, p3, p4), tags = TRUE)
}
Run the code above in your browser using DataLab