Skip to content

Commit

Permalink
Plotting normality of residuals: Scaling issues / differences (#345)
Browse files Browse the repository at this point in the history
* Plotting normality of residuals: Scaling issues / differences
Fixes #335

* revert

* adjust y scale

* minor
  • Loading branch information
strengejacke authored Jun 10, 2024
1 parent 3687f60 commit 69062ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 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.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 @@ -276,6 +276,11 @@ plot.see_check_normality <- function(x,
} 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 @@ plot.see_check_normality <- function(x,
)
},
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

0 comments on commit 69062ab

Please sign in to comment.