Skip to content

Commit

Permalink
Fix facets ordering in ggcoef_compare() (#427)
Browse files Browse the repository at this point in the history
Co-authored-by: Joseph <[email protected]>
  • Loading branch information
larmarange authored Oct 25, 2021
1 parent 3918c50 commit 8072493
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug fixes

* Reverse ordering of y-axis in `ggally_count()` (#420)
* Facets ordering in `ggcoef_compare()` (#426)


# GGally 2.1.2
Expand Down
3 changes: 2 additions & 1 deletion R/ggcoef_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ ggcoef_compare <- function (
tidyr::complete(
.data$model,
tidyr::nesting(
!!sym("variable"), !!sym("var_label"), !!sym("var_class"),
!!sym("var_label"), !!sym("variable"), !!sym("var_class"),
!!sym("var_type"), !!sym("contrasts"), !!sym("reference_row"),
!!sym("label"), !!sym("label_light")
)
Expand Down Expand Up @@ -520,6 +520,7 @@ ggcoef_data <- function (
data <- data[!is.na(data$estimate), ]

data$var_label <- forcats::fct_inorder(data$var_label)
data$variable <- forcats::fct_inorder(data$variable)
data$label <- forcats::fct_inorder(data$label)

data$label_light <- dplyr::if_else(
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-ggcoef_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,15 @@ test_that("ggcoef_model works with tieders not returning p-values", {
)

})

test_that("ggcoef_compare complete missing data by respecting the order if variables", {
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)
res <- ggcoef_compare(models = list(m1, m2, m3), return_data = TRUE)
expect_equal(
res$variable[1:4],
structure(1:4, .Label = c("Education", "Catholic", "Agriculture",
"Infant.Mortality"), class = "factor")
)
})

0 comments on commit 8072493

Please sign in to comment.