I hope this comes as an easy question for some of you. I am basically plotting the Average Marginal Effects of several variables based on a logistic regression:
summary(AMElogmodel1 <- glm(Smartphone ~ sf_group + sf_sex + age + sf_marital + sf_big + sf_hhsize,
data = Selectsfinal, family = binomial(link = "logit"), na.action = na.exclude))
And then, in order to have the plot with ggplot instead of the default AME plot for this cases I did this (mainly because I wanted to revert the X and Y axis):
xxx <- summary(margins(AMElogmodel1))
ggplot(data = xxx) +
geom_point(aes(factor, AME)) +
geom_errorbar(aes(x = factor, ymin = lower, ymax = upper)) +
geom_hline(yintercept = 0) +
coord_flip() +
theme_minimal() +
labs(x='Variable', y ="Average marginal effect")
As you can see, the names displayed there are the technical names for the variables and their categories. I imagine that if I change their names and labels this would work, but then it would mess with all my other code. Is there a way to change the names? So instead of sf_sexMale, Male and instead of age66-76, Age 66-76? Also, is there a way to change the order in which they are displayed?
Thank you very much for your help.