【问题标题】:How to reverse the legend order in a plot created with sjPlot如何在使用 sjPlot 创建的图中反转图例顺序
【发布时间】:2021-01-30 15:01:18
【问题描述】:

我使用 mtcars 的数据构建了一个lmer 模型如下。 问题是当我使用sjplot::plot_model 绘制边际效应图时,我发现图例的顺序是颠倒的。预期的顺序是低值在底部,大值在顶部。你能帮我解决吗?感谢所有关注这个问题的人。

mdl <- lmer(disp~mpg:wt+vs+(1|cyl) , data = mtcars)

sjplot::plot_model(mdl,type = 'pred',terms = c("mpg [all]","wt"))

【问题讨论】:

    标签: r ggplot2 sjplot


    【解决方案1】:

    由于您基本上处理的是ggplot,您可以通过guide_legend 颠倒图例的顺序:

    library(lme4)
    #> Loading required package: Matrix
    library(ggplot2)
    
    mdl <- lmer(disp~mpg:wt+vs+(1|cyl) , data = mtcars)
    
    sjPlot::plot_model(mdl,type = 'pred',terms = c("mpg [all]","wt")) +
      guides(color = guide_legend(reverse = TRUE))
    

    【讨论】:

      猜你喜欢
      • 2016-04-07
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多