【发布时间】:2022-11-11 00:04:15
【问题描述】:
我正在尝试使用 sjPlot 包中的 plot_model() 函数制作一些模型图。
默认设置是按字母顺序排列术语,这对我的数据(响应丰富和基线的动物行为)不合逻辑。
函数 order.terms 只是没有重新排序术语,使用 scale_x_discrete(limits= ...) 正在重新排序标签,而不是它们相应的绘图数据。详情如下:
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))
然后,我按照此海报的答案中发布的建议解决了同样的问题: https://stackoverflow.com/questions/66212389/order-terms-does-not-reorder-terms-in-sjplots-plot-model
这是尝试使用 + scale_x_discrete(limits=c...) 重新排序条款:
`
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))
您会看到 x 轴标签已重新排序,但查看 2 个图表您会发现实际数据尚未重新排序。
有没有人对如何重新排序条款并让条款对应的数据与他们一起重新排序有任何建议?
【问题讨论】: