Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New x_limits argument #307

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 37 additions & 11 deletions R/plot.check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
dataplot$grp <- rep(seq_len(ncol(x)), each = nrow(x))

attr(dataplot, "info") <- list(
"xlab" = attr(x, "response_name"),
"ylab" = ifelse(identical(type, "density"), "Density", "Counts"),
"title" = "Posterior Predictive Check",
"check_range" = attr(x, "check_range"),
"bandwidth" = attr(x, "bandwidth"),
"model_info" = attr(x, "model_info")
xlab = attr(x, "response_name"),
ylab = ifelse(identical(type, "density"), "Density", "Counts"),
title = "Posterior Predictive Check",
check_range = attr(x, "check_range"),
bandwidth = attr(x, "bandwidth"),
model_info = attr(x, "model_info")
)

class(dataplot) <- unique(c("data_plot", "see_performance_pp_check", class(dataplot)))
Expand All @@ -45,13 +45,15 @@
#' (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
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).

Check warning on line 56 in R/plot.check_predictions.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_predictions.R,line=56,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examplesIf require("performance")
#' model <- lm(Sepal.Length ~ Species * Petal.Width + Petal.Length, data = iris)
Expand All @@ -75,12 +77,13 @@
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)
plot_type <- attributes(x)$type

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {

Check warning on line 86 in R/plot.check_predictions.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_predictions.R,line=86,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
type <- plot_type
} else {
type <- match.arg(type)
Expand All @@ -90,7 +93,16 @@
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,12 +124,13 @@
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)
plot_type <- attributes(x)$type

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {

Check warning on line 133 in R/plot.check_predictions.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_predictions.R,line=133,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
type <- plot_type
} else {
type <- match.arg(type)
Expand All @@ -127,7 +140,16 @@
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_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 @@
)
}

if (!is.null(x_limits)) {
out <- out + ggplot2::coord_cartesian(xlim = x_limits)
}

out
}

Expand Down Expand Up @@ -393,13 +419,13 @@

replicated <- rbind(
data.frame(
x = sapply(x[which(names(x) != "y")], min),
x = vapply(x[which(names(x) != "y")], min, numeric(1)),
group = "Minimum",
color = "Model-predicted data",
stringsAsFactors = FALSE
),
data.frame(
x = sapply(x[which(names(x) != "y")], max),
x = vapply(x[which(names(x) != "y")], max, numeric(1)),
group = "Maximum",
color = "Model-predicted data",
stringsAsFactors = FALSE
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.

Loading