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

Plotting normality of residuals: Scaling issues / differences #345

Merged
merged 4 commits into from
Jun 10, 2024
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.4.3
Version: 0.8.4.4
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# see 0.8.5

## Minor Changes

* Improved scaling for detrended QQ plots when package *qqplotr* is not installed.
The normal and the detrended QQ plots are now visually more similar.

# see 0.8.4

## Minor Changes
Expand Down
15 changes: 13 additions & 2 deletions R/plot.check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#'
#' @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 29 in R/plot.check_normality.R

View workflow job for this annotation

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

file=R/plot.check_normality.R,line=29,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

Check warning on line 29 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_normality.R,line=29,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examples
#' library(performance)
Expand Down Expand Up @@ -276,6 +276,11 @@
} else {
insight::format_alert("For confidence bands, please install `qqplotr`.")

# to scale the detrended qq plot
N <- length(x$y)
SD <- stats::sd(x$y) * sqrt((N - 1) / N)
y_range <- round(range(x$y), 1)

gg_init <- ggplot2::ggplot(x, ggplot2::aes(sample = .data$y))

qq_stuff <- list(
Expand All @@ -294,13 +299,19 @@
)
},
ggplot2::geom_qq(
mapping = if (detrend) ggplot2::aes(y = ggplot2::after_stat(.data$sample) - ggplot2::after_stat(.data$theoretical)),
mapping = if (detrend) ggplot2::aes(
x = ggplot2::after_stat(.data$theoretical * SD),
y = ggplot2::after_stat(.data$sample - .data$theoretical * SD)
),
shape = 16,
na.rm = TRUE,
stroke = 0,
size = size_point,
colour = colors[2]
)
),
if (detrend) {
ggplot2::ylim(y_range)
}
)

if (detrend) {
Expand Down
Loading