From dd617164cd233561bba01123b0277d140ae8f62b Mon Sep 17 00:00:00 2001 From: Katarzyna Pekala Date: Thu, 9 Jul 2020 16:02:29 +0200 Subject: [PATCH] changed aspects_on_axis to show_features in plot.aspect_importance --- NEWS.md | 3 ++- R/aspect_importance.R | 13 ++++++++----- man/plot.aspect_importance.Rd | 6 +++++- tests/testthat/test_aspect_importance.R | 2 +- vignettes/vignette_aspect_importance_indepth.Rmd | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index befc766..cb84882 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,8 @@ patchwork 1.0.1 to change in DALEX 1.2.1) * added parameter to change correlation method in group_variables, cluster_variables, triplot - +* deprecated aspects_on_axis argument in plot.aspect_importance (now it’s +show_features) (#14) # triplot 1.2 diff --git a/R/aspect_importance.R b/R/aspect_importance.R index 1c71db8..6ed6f6e 100644 --- a/R/aspect_importance.R +++ b/R/aspect_importance.R @@ -234,8 +234,10 @@ aspect_importance.default <- function(x, data, #' #' @param x object of aspect_importance class #' @param bar_width bar width -#' @param aspects_on_axis if TRUE, labels on axis Y show aspect names, otherwise +#' @param show_features if TRUE, labels on axis Y show aspect names, otherwise #' they show features names +#' @param aspects_on_axis alias for \code{show_features} held for backwards +#' compatibility #' @param add_importance if TRUE, plot is annotated with values of aspects #' importance #' @param digits_to_round integer indicating the number of decimal places used @@ -278,6 +280,7 @@ aspect_importance.default <- function(x, data, plot.aspect_importance <- function(x, ..., bar_width = 10, + show_features = aspects_on_axis, aspects_on_axis = TRUE, add_importance = FALSE, digits_to_round = 2, @@ -300,7 +303,7 @@ plot.aspect_importance <- function(x, ..., bar_width = 10, # reformat features list -------------------------------------------------- - if (!aspects_on_axis) { + if (!show_features) { x$features <- sapply(x$features, paste0, collapse = ", ") } @@ -318,7 +321,7 @@ plot.aspect_importance <- function(x, ..., bar_width = 10, # prep plot --------------------------------------------------------------- - if (aspects_on_axis) { + if (show_features) { p <- ggplot(x, aes(variable_groups, ymin = 0, ymax = importance, color = a_sign)) + geom_linerange(size = bar_width) + @@ -330,12 +333,12 @@ plot.aspect_importance <- function(x, ..., bar_width = 10, facet_wrap(~label, scales = "free_y", nrow = 1) } - if (add_importance & aspects_on_axis) { + if (add_importance & show_features) { p <- p + geom_text(aes(x = variable_groups, y = importance, label = round(importance, digits_to_round), hjust = hjust), vjust = 0.5, color = "#371ea3", size = text_size) - } else if (add_importance & !aspects_on_axis) { + } else if (add_importance & !show_features) { p <- p + geom_text(aes(x = features, y = importance, label = round(importance, digits_to_round), hjust = hjust), diff --git a/man/plot.aspect_importance.Rd b/man/plot.aspect_importance.Rd index 72ecb2f..83a1f41 100644 --- a/man/plot.aspect_importance.Rd +++ b/man/plot.aspect_importance.Rd @@ -8,6 +8,7 @@ x, ..., bar_width = 10, + show_features = aspects_on_axis, aspects_on_axis = TRUE, add_importance = FALSE, digits_to_round = 2, @@ -21,9 +22,12 @@ \item{bar_width}{bar width} -\item{aspects_on_axis}{if TRUE, labels on axis Y show aspect names, otherwise +\item{show_features}{if TRUE, labels on axis Y show aspect names, otherwise they show features names} +\item{aspects_on_axis}{alias for \code{show_features} held for backwards +compatibility} + \item{add_importance}{if TRUE, plot is annotated with values of aspects importance} diff --git a/tests/testthat/test_aspect_importance.R b/tests/testthat/test_aspect_importance.R index ce5c28c..b9fe4d7 100644 --- a/tests/testthat/test_aspect_importance.R +++ b/tests/testthat/test_aspect_importance.R @@ -164,7 +164,7 @@ test_that("check plot (facets) for aspects importance",{ expect_is(plot(aspect_importance_apartments1, aspect_importance_apartments2, aspect_importance_apartments3, add_importance = TRUE, - aspects_on_axis = FALSE, digits_to_round = 0), "gg") + show_features = FALSE, digits_to_round = 0), "gg") }) diff --git a/vignettes/vignette_aspect_importance_indepth.Rmd b/vignettes/vignette_aspect_importance_indepth.Rmd index 97c183e..06761fa 100644 --- a/vignettes/vignette_aspect_importance_indepth.Rmd +++ b/vignettes/vignette_aspect_importance_indepth.Rmd @@ -189,7 +189,7 @@ print(Boston_ai_lm_2, show_features = TRUE) print(Boston_ai_rf_2, show_features = TRUE) -plot(Boston_ai_lm_2, Boston_ai_rf_2, aspects_on_axis = FALSE) +plot(Boston_ai_lm_2, Boston_ai_rf_2, show_features = FALSE) ```