Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using facet_wrap with glmmTMB model #147

@5tokesy

Description

@5tokesy

I’ve created a model using the glmmTMB package which produces acceptable results. My model uses several years of data. The years are included as a random intercept.

I have plotted the model using jtools. I’m happy with the combined year plot. Next, I want to plot the individual years using GGPLOT’s facet_wrap function.

library(jtools)
library(ggplot2)
library(glmmTMB)
data(mpg)
fit <- glmmTMB(cty ~ displ + (1 | year), data = mpg)
jtools::effect_plot(fit, pred = displ, 
                    interval = TRUE, 
                    groups = list(year = unique(mpg$year)))

I've tried a few variations on the following code:

effect_plot(
  fit, 
  pred = displ, 
  interval = TRUE, 
  groups = unique(mpg$year))

I've also tried using '+ facet_wrap(~year, ncol = 2)' but it produces the same plot given in my example code.

Thanks for any suggestions.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions