diff --git a/DESCRIPTION b/DESCRIPTION index 247febd..701e147 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -60,7 +60,8 @@ Suggests: tibble, withr, quarto, - spelling + spelling, + vdiffr Config/testthat/edition: 3 Encoding: UTF-8 RoxygenNote: 7.3.2 diff --git a/R/summarize_cat_cat_data.R b/R/summarize_cat_cat_data.R index aeca463..96c278c 100644 --- a/R/summarize_cat_cat_data.R +++ b/R/summarize_cat_cat_data.R @@ -3,9 +3,11 @@ # Helper function to create overarching factor variable for the response categories column category_var_as_fct <- function(data_summary, fct_unions) { + data_summary$.category <- factor(x = data_summary$.category, levels = fct_unions, - labels = fct_unions) + labels = fct_unions, + exclude = NULL) data_summary } diff --git a/tests/testthat/_snaps/make_content.cat_plot_html/unused-categories-in-legend.svg b/tests/testthat/_snaps/make_content.cat_plot_html/unused-categories-in-legend.svg new file mode 100644 index 0000000..74a7241 --- /dev/null +++ b/tests/testthat/_snaps/make_content.cat_plot_html/unused-categories-in-legend.svg @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +55 +29 +20 +53 +25 +18 + + + + + + + + + + + + + + + + + +47 +35 +30 +47 +35 +6 + + + + + + + + + + + + + + + + + +45 +41 +25 +41 +30 +18 + + + + + + + + + + + + + + + + + +41 +40 +20 +18 +40 +41 + + + + + + + + + + + +Red Party + + + + + + + + + + +Yellow Party + + + + + + + + + + +Green Party + + + + + + + + + + +Blue Party + + + + + + + +0% +25% +50% +75% +100% +Males +Females + + +Females +Males + + +Males +Females + + +Females +Males + + +.proportion +x1_sex + + + + + + + + + +Strongly disagree +Somewhat disagree +Somewhat agree +Strongly agree +Unused categories in legend + + diff --git a/tests/testthat/test-make_content.cat_plot_html.R b/tests/testthat/test-make_content.cat_plot_html.R new file mode 100644 index 0000000..7fda682 --- /dev/null +++ b/tests/testthat/test-make_content.cat_plot_html.R @@ -0,0 +1,8 @@ +testthat::test_that("show.legend works with unused categories", { + vdiffr::expect_doppelganger(title = "Unused categories in legend", + fig = { + saros.contents::ex_survey |> + dplyr::filter(dplyr::if_all(p_1:p_4, ~.x != "Strongly agree")) |> + saros.contents::makeme(dep=p_1:p_4, indep=x1_sex) + }) +})