diff --git a/NEWS.md b/NEWS.md index dd574ac1aa..85496607a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 (development version) +* New default `geom_qq_line(geom = "abline")` for better clipping in the + vertical direction. In addition, `slope` and `intercept` are new computed + variables in `stat_qq_line()` (@teunbrand, #6087). * `guide_*()` can now accept two inside legend theme elements: `legend.position.inside` and `legend.justification.inside`, allowing inside legends to be placed at different positions. Only inside legends with the same diff --git a/R/stat-qq-line.R b/R/stat-qq-line.R index 8133216779..ab6c194cfe 100644 --- a/R/stat-qq-line.R +++ b/R/stat-qq-line.R @@ -6,7 +6,7 @@ #' the data geom_qq_line <- function(mapping = NULL, data = NULL, - geom = "path", + geom = "abline", position = "identity", ..., distribution = stats::qnorm, @@ -86,6 +86,9 @@ StatQqLine <- ggproto("StatQqLine", Stat, x <- range(theoretical) } - data_frame0(x = x, y = slope * x + intercept) + data_frame0( + x = x, y = slope * x + intercept, + slope = slope, intercept = intercept + ) } ) diff --git a/R/stat-qq.R b/R/stat-qq.R index 4ffab00320..71068bbd04 100644 --- a/R/stat-qq.R +++ b/R/stat-qq.R @@ -22,7 +22,9 @@ #' x = "x-coordinates of the endpoints of the line segment connecting the #' points at the chosen quantiles of the theoretical and the sample #' distributions.", -#' y = "y-coordinates of the endpoints." +#' y = "y-coordinates of the endpoints.", +#' slope = "Amount of change in `y` across 1 unit of `x`.", +#' intercept = "Value of `y` at `x == 0`." #' ) #' #' @export diff --git a/man/geom_qq.Rd b/man/geom_qq.Rd index d6bedf3427..88656bc53a 100644 --- a/man/geom_qq.Rd +++ b/man/geom_qq.Rd @@ -10,7 +10,7 @@ geom_qq_line( mapping = NULL, data = NULL, - geom = "path", + geom = "abline", position = "identity", ..., distribution = stats::qnorm, @@ -25,7 +25,7 @@ geom_qq_line( stat_qq_line( mapping = NULL, data = NULL, - geom = "path", + geom = "abline", position = "identity", ..., distribution = stats::qnorm, @@ -205,6 +205,8 @@ Variables computed by \code{stat_qq_line()}: \itemize{ \item \code{after_stat(x)}\cr x-coordinates of the endpoints of the line segment connecting the points at the chosen quantiles of the theoretical and the sample distributions. \item \code{after_stat(y)}\cr y-coordinates of the endpoints. +\item \code{after_stat(slope)}\cr Amount of change in \code{y} across 1 unit of \code{x}. +\item \code{after_stat(intercept)}\cr Value of \code{y} at \code{x == 0}. } }