Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order of facets in ggcoef_compare() #426

Closed
guyabel opened this issue Oct 23, 2021 · 3 comments · Fixed by #427
Closed

order of facets in ggcoef_compare() #426

guyabel opened this issue Oct 23, 2021 · 3 comments · Fixed by #427

Comments

@guyabel
Copy link

guyabel commented Oct 23, 2021

Asked on community RStudio without much success.

Is there a way to control the order of the facets from a ggcoef_compare() plot?

library(GGally)
m1 <- lm(Fertility ~ Education + Catholic, data = swiss)
m2 <- lm(Fertility ~ Education + Catholic + Agriculture, data = swiss)
m3 <- lm(Fertility ~ Education + Catholic + Agriculture + Infant.Mortality, data = swiss)
ggcoef_compare(models = list(m1, m2, m3))

image

Would it not be more intuitive if the facets followed a default order of the variables entering the model building process (Education, Catholic, Agriculture, Infant.Mortality in the example above) ?

@larmarange
Copy link
Contributor

Should be fixed in #427

library(GGally)
#> Le chargement a nécessité le package : ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
m1 <- lm(Fertility ~ Education + Catholic, data = swiss)
m2 <- lm(Fertility ~ Education + Catholic + Agriculture, data = swiss)
m3 <- lm(Fertility ~ Education + Catholic + Agriculture + Infant.Mortality, data = swiss)
ggcoef_compare(models = list(m1, m2, m3))

Created on 2021-10-24 by the reprex package (v2.0.1)

@larmarange
Copy link
Contributor

larmarange commented Oct 24, 2021

In the meantime, you will find below a way to control the order of the facets with the current version of GGally. You need call directly ggcoef_plot() and to pass a data frame ordered the way you want the facets being displayed.

library(GGally) # current stable version
#> Le chargement a nécessité le package : ggplot2
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
library(tidyverse)
m1 <- lm(Fertility ~ Education + Catholic, data = swiss)
m2 <- lm(Fertility ~ Education + Catholic + Agriculture, data = swiss)
m3 <- lm(Fertility ~ Education + Catholic + Agriculture + Infant.Mortality, data = swiss)

# incorrect order
ggcoef_compare(models = list(m1, m2, m3))

# temporary fix
d <- ggcoef_compare(models = list(m1, m2, m3), return_data = TRUE)
d <- d %>% arrange(model, var_label)
ggcoef_plot(d, colour = "model", dodged = TRUE)

Created on 2021-10-24 by the reprex package (v2.0.1)

@guyabel
Copy link
Author

guyabel commented Oct 26, 2021

Great. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants