# Visualize cross over interaction logistic regression categorical variable in R

I have performed a logistic regression with the following variables:

• X: Categorical with three levels (St, An, Int)
• M: Moderator, which has two levels (Mob,Desk)
• Y: Dichotomous dependent variable (0/1)

I found no main effect of X on Y or of M on Y but I did find a significant interaction effect between level 'Int' of X with M.

Hence, I want to show a graph in which I show the cross over interaction but I can't figure out how.

I already read this question (Plotting logistic regression interaction (categorical) in R) but I couldn't rewrite this to my own dataset.

PS: I am using R in case anyone would kindly like to provide an example.

There could be many ways. One of them is to compute the predicted odds, and turn that into probability for each possible combination between X and M. Here is a short example:

set.seed(144)

x <- as.factor(sample(c(1,2,3), 100, replace=T))
m <- as.factor(sample(c(1,1,2,2,2), 100, replace=T))
y <- sample(c(1,0), 100, replace=T)

m1 <- glm(y ~ x*m, family=binomial)

possibleCombo=data.frame(x = c(1,2,3,1,2,3), m = c(1,1,1,2,2,2))

yhatProb <- predict(m1, possibleCombo, type="response")*100

possibleCombo <- data.frame(possibleCombo,yhatProb)

library(ggplot2)
p1 <- ggplot(possibleCombo, aes(factor(x),yhatProb)) +
geom_bar(aes(fill=factor(m)), position="dodge", stat="identity")
p1


The result looks something like this: 