From edc676956680bd800e98f91f5bfb0653e8316450 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 28 Sep 2023 12:00:09 +0200 Subject: [PATCH] New x_limits argument --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/plot.check_predictions.R | 32 ++++++++++++++++++++++++--- man/print.see_performance_pp_check.Rd | 5 +++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e9e503b35..2aa7ccf94 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.8.0.4 +Version: 0.8.0.5 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index d3b1e5e47..887a59f0b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,8 @@ QQ-plot. Previous behavior can be restored by setting `type = "density"`. * Plot method for `binned_residuals()` gains a `show_smooth` argument, to show or hide the smooth line. +* Plot method for `check_predictions()` gains a `x_limits` argument, to limit + the x-axis-range. This can be useful to "zoom in" certain parts of the plot. # see 0.8.0 diff --git a/R/plot.check_predictions.R b/R/plot.check_predictions.R index 474f3b179..c117c4db3 100644 --- a/R/plot.check_predictions.R +++ b/R/plot.check_predictions.R @@ -45,6 +45,8 @@ data_plot.performance_pp_check <- function(x, type = "density", ...) { #' (default), `"discrete_dots"`, `"discrete_interval"` or `"discrete_both"` (the #' `discrete_*` options are appropriate for models with discrete - binary, integer #' or ordinal etc. - outcomes). +#' @param x_limits Numeric vector of length 2 specifying the limits of the x-axis. +#' If not `NULL`, will zoom in the x-axis to the specified limits. #' @inheritParams data_plot #' @inheritParams plot.see_check_normality #' @inheritParams plot.see_parameters_distribution @@ -75,6 +77,7 @@ print.see_performance_pp_check <- function(x, style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + x_limits = NULL, ...) { orig_x <- x check_range <- isTRUE(attributes(x)$check_range) @@ -90,7 +93,16 @@ print.see_performance_pp_check <- function(x, x <- data_plot(x, type) } - p1 <- .plot_pp_check(x, size_line, line_alpha, theme_style = style, colors = colors, type = type, ...) + p1 <- .plot_pp_check( + x, + size_line, + line_alpha, + theme_style = style, + colors = colors, + type = type, + x_limits = x_limits, + ... + ) if (isTRUE(check_range)) { p2 <- .plot_pp_check_range(orig_x, size_bar, colors = colors) @@ -112,6 +124,7 @@ plot.see_performance_pp_check <- function(x, style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + x_limits = NULL, ...) { orig_x <- x check_range <- isTRUE(attributes(x)$check_range) @@ -127,7 +140,16 @@ plot.see_performance_pp_check <- function(x, x <- data_plot(x, type) } - p1 <- .plot_pp_check(x, size_line, line_alpha, theme_style = style, colors = colors, type = type, ...) + p1 <- .plot_pp_check( + x, + size_line, + line_alpha, + theme_style = style, + colors = colors, + type = type, + x_limits = x_limits, + ... + ) if (isTRUE(check_range)) { p2 <- .plot_pp_check_range(orig_x, size_bar, colors = colors) @@ -139,7 +161,7 @@ plot.see_performance_pp_check <- function(x, -.plot_pp_check <- function(x, size_line, line_alpha, theme_style, colors, type = "density", ...) { +.plot_pp_check <- function(x, size_line, line_alpha, theme_style, colors, type = "density", x_limits = NULL, ...) { info <- attr(x, "info") # default bandwidth, for smooting @@ -182,6 +204,10 @@ plot.see_performance_pp_check <- function(x, ) } + if (!is.null(x_limits)) { + out <- out + ggplot2::coord_cartesian(xlim = x_limits) + } + out } diff --git a/man/print.see_performance_pp_check.Rd b/man/print.see_performance_pp_check.Rd index 6bcc1335c..47765a8f4 100644 --- a/man/print.see_performance_pp_check.Rd +++ b/man/print.see_performance_pp_check.Rd @@ -13,6 +13,7 @@ style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + x_limits = NULL, ... ) @@ -24,6 +25,7 @@ style = theme_lucid, colors = unname(social_colors(c("green", "blue"))), type = c("density", "discrete_dots", "discrete_interval", "discrete_both"), + x_limits = NULL, ... ) } @@ -46,6 +48,9 @@ hex-format) for points and line.} \verb{discrete_*} options are appropriate for models with discrete - binary, integer or ordinal etc. - outcomes).} +\item{x_limits}{Numeric vector of length 2 specifying the limits of the x-axis. +If not \code{NULL}, will zoom in the x-axis to the specified limits.} + \item{...}{Arguments passed to or from other methods.} } \value{