Skip to content

Commit

Permalink
New x_limits argument
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 28, 2023
1 parent 9587914 commit edc6769
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 29 additions & 3 deletions R/plot.check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions man/print.see_performance_pp_check.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit edc6769

Please sign in to comment.