【问题标题】:Neither order.terms or scale_x_discrete reorders terms in sjPlot's plot_model()order.terms 或 scale_x_discrete 都不会重新排序 sjPlot 的 plot_model() 中的术语
【发布时间】: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 个图表您会发现实际数据尚未重新排序。

有没有人对如何重新排序条款并让条款对应的数据与他们一起重新排序有任何建议?

【问题讨论】:

    标签: r sjplot x-axis


    【解决方案1】:

    order.terms 用于包含多个列时。如果要对列中的级别进行排序,则需要将其设为有序因子。看看我的例子。

    第一个情节将教育领域作为一个因素,自然地按字母顺序排列了两个级别:高和低。

    cuse = read.table("https://data.princeton.edu/wws509/datasets/cuse.dat", 
                      header = TRUE)
    
    cuse <- mutate(cuse, across(1:3, as.factor))
    
    lai <- geeglm(cbind(using, notUsing) ~ age + education, id = wantsMore,
                  data = cuse, family = "binomial")
    plot_model(lai, type = "pred", terms = "education")
    

    现在,如果将其设为有序因子,并声明低在高之前,那么我可以切换它们在图中的显示方式。

    cuse2 <- mutate(cuse, across(c(1, 3), as.factor), 
                    education = ordered(education, c("low", "high")))
    
    lai2 <- geeglm(cbind(using, notUsing) ~ age + education, id = wantsMore,
                  data = cuse2, family = "binomial")
    plot_model(lai2, type = "pred", terms = "education")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多