Skip to content
Draft
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
27 changes: 27 additions & 0 deletions R/stat_qq_point.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#' the objects will be detrended according to the reference Q-Q line. This
#' procedure was described by Thode (2002), and may help reducing visual bias
#' caused by the orthogonal distances from Q-Q points to the reference line.
#' @param downsample Logical. Only used if \code{downsample = TRUE}.
#' Should the number of data points in the figure be, reduced? If \code{TRUE},
#' datapoints will be removed based on proximity quantified by downf.
#' @param downf Double. Fraction of maximum distance in quantile data within
#' which data points will be discarded during down sampling.
#' @param identity Logical. Only used if \code{detrend = TRUE}. Should an
#' identity line be used as the reference line for the plot detrending? If
#' \code{TRUE}, the points will be detrended according to the reference
Expand Down Expand Up @@ -74,6 +79,8 @@ stat_qq_point <- function(
distribution = "norm",
dparams = list(),
detrend = FALSE,
downsample = FALSE,
downf = 0.001,
identity = FALSE,
qtype = 7,
qprobs = c(.25, .75),
Expand Down Expand Up @@ -132,6 +139,8 @@ stat_qq_point <- function(
distribution = distribution,
dparams = dparams,
detrend = detrend,
downsample = downsample,
downf = downf,
identity = identity,
qtype = qtype,
qprobs = qprobs,
Expand Down Expand Up @@ -164,6 +173,8 @@ StatQqPoint <- ggplot2::ggproto(
distribution = "norm",
dparams = list(),
detrend = FALSE,
downsample = FALSE,
downf = 0.001,
identity = FALSE,
qtype = 7,
qprobs = c(.25)) {
Expand Down Expand Up @@ -250,6 +261,22 @@ StatQqPoint <- ggplot2::ggproto(
out <- data.frame(sample = smp, theoretical = theoretical)
}

if (downsample) {
res <- norm(as.matrix(apply(out, 2, max)
- apply(out, 2, min)), type="2") * downf
keep <- rep(TRUE, nrow(out))
j <- 1
for(i in 2:nrow(out)) {
d <- norm(as.matrix(out[i, ] - out[j, ]), type="2")
if (d < res) {
keep[i] <- FALSE
} else {
j <- i
}
}
out <- out[keep, ]
}

if (!is.null(data$label)) out$label <- data$label[oidx]
out
}
Expand Down
9 changes: 9 additions & 0 deletions man/stat_qq_point.Rd

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