I'm trying to produce a marginal effects plot from a logistic regression I ran, using plot_model (sjPlot), from publicly available survey data. The predictor for the plot is binary (male or female) and the response variable is whether a respondent votes for a Green party.
This is the code:
logit3 %>%
plot_model(
type = "pred",
terms = "female"
)
labs(
x = "Gender",
y = "Predicted probability of voting Green",
title = "Predicted probability of voting Green by gender"
)
And this is the plot:
The plot produces fine but, since this is a binary predictor, I would like it as two separate points (for male and female), with confidence intervals, rather than than a linear line between the two.
I'm sure this has an easy answer and that I'm just being stupid, but I can't seem to find anything online. I also haven't posted much on this forum, so please let me know if I need to provide anything else.
Thanks
CodePudding user response:
Sorry for not posting a reprex. Specifying the predictor using factor() solved the problem, thank you! I had previously tried using as.factor(), which didn't work.
library(sjPlot)
mtcars$am <- factor(mtcars$am)
m <- glm(vs ~ am, mtcars, family = 'binomial')
plot_model(m, type = "pred", terms = "am")