IndrajeetPatil / ggstatsplot

Enhancing {ggplot2} plots with statistical analysis 📊📣
https://indrajeetpatil.github.io/ggstatsplot/
GNU General Public License v3.0
2.03k stars 190 forks source link

Reversing sort order #642

Open IsadoraBM opened 3 years ago

IsadoraBM commented 3 years ago

Model terms are presented in inverse order to dataframe. e.g Sepal.Width 1st, Petal.Width last in summary, but Petal.Width is on top in plot. sort = "ascending" sorts in effect size terms, but there is no equivalent to fct_rev to sort by model's order.

test <- iris%>% mutate(LengthDummy= if_else(Sepal.Length>5, "Long", "Short") %>% as_factor(.)) %>%  
  bife(LengthDummy~ Sepal.Width+ Petal.Length+Petal.Width
       | Species, data = ., "logit")
summary(test)
ggstatsplot::ggcoefstats(test)
IndrajeetPatil commented 2 years ago

Good point! {sjPlot} does it correctly. I will try to fix this ASAP.

library(tidyverse)
library(bife)

test <- iris %>%
  mutate(LengthDummy = if_else(Sepal.Length > 5, "Long", "Short") %>% as_factor(.)) %>%
  bife(LengthDummy ~ Sepal.Width + Petal.Length + Petal.Width |
    Species, data = ., "logit")

parameters::parameters(test)
#> # Fixed Effects
#> 
#> Parameter    | Log-Odds |   SE |          95% CI |     z |      p
#> -----------------------------------------------------------------
#> Sepal Width  |    -9.46 | 2.76 | [-14.86, -4.05] | -3.43 | < .001
#> Petal Length |    -5.37 | 2.02 | [ -9.32, -1.42] | -2.67 | 0.008 
#> Petal Width  |    -0.64 | 3.46 | [ -7.42,  6.13] | -0.19 | 0.852
#> 
#> Uncertainty intervals (equal-tailed) and p values (two-tailed) computed using a
#>   Wald z-distribution approximation.
ggstatsplot::ggcoefstats(test)

sjPlot::plot_model(test)

Created on 2022-01-31 by the reprex package (v2.0.1.9000)