strengejacke / ggeffects

Estimated Marginal Means and Marginal Effects from Regression Models for ggplot2
https://strengejacke.github.io/ggeffects
Other
560 stars 36 forks source link

Add "order" or "sort" option to ggpredict plot options #339

Open jbohenek opened 1 year ago

jbohenek commented 1 year ago

Hey all,

First - I love the package. I teach it in my R course. Thanks for making such a useful package.

Would it be possible to implement an effect ordering option for plotting ggpredict objects? For example, you plot many effect estimates and you want to order them by size (either ascending or descending). Typically, one would do this by hand, but that would require remaking the prediction df and ordering variables, which is a tedious step that ggpredict allows us to skip entirely (thank god). e.g.,

ggpredict(fit, ~x) |> plot(order=T)

Ben Bolker has a utility function to do with dot whisker plots available on his github. Perhaps something similar could be implemented? https://github.com/eco4cast/Statistical-Methods-Seminar-Series/blob/main/bolker_mixedmodels/utils.R

If this option is already available, then I feel stupid :)

-Cheers J

strengejacke commented 1 week ago

This is only needed/useful for categorical focal terms, right?

jbohenek commented 1 week ago

Yes, what I currently do is convert to tibble, sort, and then construct my own ggplot.

ap_duck3_ss<-ggemmeans(gam4,~species*site) |> as_tibble() |> mutate(x = fct_reorder (x,predicted))