I'm trying to make some model plots using plot_model() function in the sjPlot package.
The default is to have the terms alphabetically, which isn't logical for my data (animal behavior in response to enrichments and in baselines).
The function order.terms just isn't reordering the terms, and using scale_x_discrete(limits= ...) is reordering the labels, but not their corresponding plotted data. Details below:
I initially tried using the order.terms function (based on the order of the terms in the model summary):
#model
lai<-geeglm(point.lai ~ ee2 + Observer + month,
data = noday3,
id = ferret.id,
family = binomial,
corstr = "exchangeable")
#plot
plot_model(lai, type="pred", terms = c("ee2"),
title = c(""),
axis.title = c("EE on Day 1 and Baselines", "Probability (%) of Lying awake inattentive"),
auto.label = F,
order.terms = c(4,3,1,2,5,7,6))
You'll see this isn't successful:
I then followed the advice posted in the answer to this poster struggling with the same issue: https://stackoverflow.com/questions/66212389/order-terms-does-not-reorder-terms-in-sjplots-plot-model
which was to try using + scale_x_discrete(limits=c...)
to re-order the terms:
P <- plot_model(lai, type="pred", terms = c("ee2"),
title = c(""),
axis.title = c("EE on Day 1 and Baselines", "Probability (%) of Lying awake inattentive"),
auto.label = F)
P + theme_bw()+
scale_x_discrete(limits=c("bl.b","bl.a","bag", "bed", "box", "digbox", "complex"),
labels=c("bl.b"="Baseline \n (Pre)","bl.a"="Baseline \n (Post)","bag"="Bag", "bed"="Bed", "box"="Box", "digbox"="Dig-box", "complex"="Complex \n environment"))+
theme(axis.text.x = element_text(size=14),
axis.text.y = element_text(size=14),
axis.title.x = element_text(size = 16),
axis.title.y = element_text(size = 16))
You'll see that the x axis labels have been reordered, but looking at the 2 graphs you'll see that the actual data hasn't been reordered.
Does anyone have any advice on how to reorder the terms and have the terms corresponding data be reordered with them?