Skip to content

Plotting contrasts for categorical model with interaction #267

@a-difabio

Description

@a-difabio

When plotting contrasts for a model with an interaction term between two categorical variables, is it possible to split the lighthouse plots into facets?

It seems to me that the contrast are correctly calculated, but the output plot is not what I would expect.

library(ggplot2)
library(modelbased)
library(see)
data("Arabidopsis", package = "lme4")

model = lm(total.fruits ~ amd*status, Arabidopsis)
means = estimate_means(model)
#> We selected `by = c("amd", "status")`.
contrasts = estimate_contrasts(model, contrast = "amd", by = "status")
contrasts
#> Marginal Contrasts Analysis
#> 
#> Level1  |    Level2 |      status | Difference |          95% CI |   SE | t(619) |     p
#> ----------------------------------------------------------------------------------------
#> clipped | unclipped |      Normal |      -5.73 | [-14.02,  2.56] | 4.22 |  -1.36 | 0.175
#> clipped | unclipped | Petri.Plate |      -4.62 | [-21.61, 12.38] | 8.65 |  -0.53 | 0.594
#> clipped | unclipped |  Transplant |       0.37 | [-12.48, 13.21] | 6.54 |   0.06 | 0.955
#> 
#> Marginal contrasts estimated at amd
#> p-value adjustment method: Holm (1979)

plot(contrasts, means) +
    facet_wrap(vars(status))

Created on 2024-10-28 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Plot 🎇Something related to plotting

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions