From fcb386baefe59035ed55c87b3b25b9a22e523b34 Mon Sep 17 00:00:00 2001 From: "Brenton M. Wiernik" Date: Sun, 23 Jul 2023 14:19:41 -0400 Subject: [PATCH] Update labeling and defaults - Make titles for p-p plots parallel to those for q-q plots - Change default to `type = "qq"` - Add details for the `type` argument to documentation (and add similar details for functions that previously imported the `type` argument from `plot.see_check_normality` --- R/plot.check_normality.R | 18 +++++++++++------- R/plot.check_outliers.R | 6 ++++++ R/plot.n_factors.R | 6 ++++++ R/plot.parameters_pca.R | 4 ++++ man/plot.see_check_normality.Rd | 12 ++++++++---- man/plot.see_check_outliers.Rd | 7 ++++++- man/plot.see_n_factors.Rd | 7 ++++++- man/plot.see_parameters_pca.Rd | 5 ++++- .../check-normality-works-lm-pp.svg | 8 ++++---- 9 files changed, 55 insertions(+), 18 deletions(-) diff --git a/R/plot.check_normality.R b/R/plot.check_normality.R index 63637c279..b4ff8750b 100644 --- a/R/plot.check_normality.R +++ b/R/plot.check_normality.R @@ -4,12 +4,16 @@ #' function. #' #' @param type Character vector, indicating the type of plot. +#' Options are `"qq"` (default) for quantile-quantile (Q-Q) plots, +#' `"pp"` for probability-probability (P-P) plots, or +#' `"density"` for density overlay plots. #' @param size_line Numeric value specifying size of line geoms. #' @param dot_alpha Numeric value specifying alpha level of the point geoms. #' @param alpha Numeric value specifying alpha level of the confidence bands. #' @param colors Character vector of length two, indicating the colors (in #' hex-format) for points and line. -#' @param detrend Logical that decides if the plot should be detrended. +#' @param detrend Logical that decides if Q-Q and P-P plots should be de-trended. +#' Defaults to `TRUE` if the *qqplotr* package is installed and `FALSE` otherwise. #' @param method The method used for estimating the qq/pp bands. Default to #' `"ell"` (equal local levels / simultaneous testing - recommended). Can also #' be one of `"pointwise"` or `"boot"` for pointwise confidence bands, or @@ -32,14 +36,14 @@ #' #' @export plot.see_check_normality <- function(x, - type = c("density", "qq", "pp"), + type = c("qq", "pp", "density"), data = NULL, size_line = 0.8, size_point = 2, alpha = 0.2, dot_alpha = 0.8, colors = c("#3aaf85", "#1b6ca8"), - detrend = FALSE, + detrend = requireNamespace("qqplotr", quietly = TRUE), method = "ell", ...) { type <- match.arg(type) @@ -302,15 +306,15 @@ plot.see_check_normality <- function(x, alpha = dot_alpha_level ) # "#2c3e50" } else { - stop("Package 'qqplotr' OR 'MASS' required for PP-plots. Please install one of them.", call. = FALSE) + stop("Package 'qqplotr' OR 'MASS' required for P-P plots. Please install one of them.", call. = FALSE) } p_plot + ggplot2::labs( - title = "Normality of Residuals (PP plot)", + title = "Normality of Residuals", subtitle = "Dots should fall along the line", - y = "Cummulative Probability", - x = "Probability Points" + y = "Sample Cummulative Probability", + x = "Standard Normal Cumulative Probability" ) + theme_style( base_size = 10, diff --git a/R/plot.check_outliers.R b/R/plot.check_outliers.R index 34afd3e6e..4cf04f5c8 100644 --- a/R/plot.check_outliers.R +++ b/R/plot.check_outliers.R @@ -3,6 +3,12 @@ #' The `plot()` method for the `performance::check_outliers()` #' function. #' +#' @param type Character vector, indicating the type of plot. +#' Options are `"dots"` (default) for a scatterplot of leverage (hat) values +#' versus residuals, with Cook's Distance contours for evaluating influential +#' points, or `"bars"` for a bar chart of (rescaled) outlier statistic values +#' for each data point. Only used for outlier plots of fitted models; for +#' outlier plots of raw data values, `type = "bars"` is always used. #' @param show_labels Logical. If `TRUE`, text labels are displayed. #' @param size_text Numeric value specifying size of text labels. #' @param rescale_distance Logical. If `TRUE`, distance values are rescaled diff --git a/R/plot.n_factors.R b/R/plot.n_factors.R index c262f3f47..b332488b5 100644 --- a/R/plot.n_factors.R +++ b/R/plot.n_factors.R @@ -66,6 +66,12 @@ data_plot.n_clusters <- data_plot.n_factors #' #' The `plot()` method for the `parameters::n_factors()` and `parameters::n_clusters()` #' +#' @param type Character vector, indicating the type of plot. +#' Options are three different shapes to illustrate the degree of consensus +#' between dimensionality methods for each number of factors; +#' `"bar"` (default) for a bar chart, +#' `"line"` for a horizontal point and line chart, or +#' `"area"` for an area chart (frequency polygon). #' @param size Depending on `type`, a numeric value specifying size of bars, #' lines, or segments. #' @inheritParams data_plot diff --git a/R/plot.parameters_pca.R b/R/plot.parameters_pca.R index d808cff7d..a0ca2c8d0 100644 --- a/R/plot.parameters_pca.R +++ b/R/plot.parameters_pca.R @@ -55,6 +55,10 @@ data_plot.parameters_efa <- data_plot.parameters_pca #' #' The `plot()` method for the `parameters::principal_components()` function. #' +#' @param type Character vector, indicating the type of plot. +#' Options are three different shapes to represent component loadings; +#' `"bar"` (default) for a horizontal bar chart, or +#' `"line"` for a horizontal point and line chart. #' @param text_color Character specifying color of text labels. #' @inheritParams data_plot #' @inheritParams plot.see_bayesfactor_parameters diff --git a/man/plot.see_check_normality.Rd b/man/plot.see_check_normality.Rd index a90c37454..56c788bef 100644 --- a/man/plot.see_check_normality.Rd +++ b/man/plot.see_check_normality.Rd @@ -6,14 +6,14 @@ \usage{ \method{plot}{see_check_normality}( x, - type = c("density", "qq", "pp"), + type = c("qq", "pp", "density"), data = NULL, size_line = 0.8, size_point = 2, alpha = 0.2, dot_alpha = 0.8, colors = c("#3aaf85", "#1b6ca8"), - detrend = FALSE, + detrend = requireNamespace("qqplotr", quietly = TRUE), method = "ell", ... ) @@ -21,7 +21,10 @@ \arguments{ \item{x}{An object.} -\item{type}{Character vector, indicating the type of plot.} +\item{type}{Character vector, indicating the type of plot. +Options are \code{"qq"} (default) for quantile-quantile (Q-Q) plots, +\code{"pp"} for probability-probability (P-P) plots, or +\code{"density"} for density overlay plots.} \item{data}{The original data used to create this object. Can be a statistical model.} @@ -37,7 +40,8 @@ statistical model.} \item{colors}{Character vector of length two, indicating the colors (in hex-format) for points and line.} -\item{detrend}{Logical that decides if the plot should be detrended.} +\item{detrend}{Logical that decides if Q-Q and P-P plots should be de-trended. +Defaults to \code{TRUE} if the \emph{qqplotr} package is installed and \code{FALSE} otherwise.} \item{method}{The method used for estimating the qq/pp bands. Default to \code{"ell"} (equal local levels / simultaneous testing - recommended). Can also diff --git a/man/plot.see_check_outliers.Rd b/man/plot.see_check_outliers.Rd index d13cd5154..ed17cce12 100644 --- a/man/plot.see_check_outliers.Rd +++ b/man/plot.see_check_outliers.Rd @@ -32,7 +32,12 @@ hex-format) for points and line.} to a range from 0 to 1. This is mainly due to better catch the differences between distance values.} -\item{type}{Character vector, indicating the type of plot.} +\item{type}{Character vector, indicating the type of plot. +Options are \code{"dots"} (default) for a scatterplot of leverage (hat) values +versus residuals, with Cook's Distance contours for evaluating influential +points, or \code{"bars"} for a bar chart of (rescaled) outlier statistic values +for each data point. Only used for outlier plots of fitted models; for +outlier plots of raw data values, \code{type = "bars"} is always used.} \item{show_labels}{Logical. If \code{TRUE}, text labels are displayed.} diff --git a/man/plot.see_n_factors.Rd b/man/plot.see_n_factors.Rd index 3d8b7db9f..4f4aa0fd5 100644 --- a/man/plot.see_n_factors.Rd +++ b/man/plot.see_n_factors.Rd @@ -12,7 +12,12 @@ \item{data}{The original data used to create this object. Can be a statistical model.} -\item{type}{Character vector, indicating the type of plot.} +\item{type}{Character vector, indicating the type of plot. +Options are three different shapes to illustrate the degree of consensus +between dimensionality methods for each number of factors; +\code{"bar"} (default) for a bar chart, +\code{"line"} for a horizontal point and line chart, or +\code{"area"} for an area chart (frequency polygon).} \item{size}{Depending on \code{type}, a numeric value specifying size of bars, lines, or segments.} diff --git a/man/plot.see_parameters_pca.Rd b/man/plot.see_parameters_pca.Rd index f5aba0f2f..15fe47d2c 100644 --- a/man/plot.see_parameters_pca.Rd +++ b/man/plot.see_parameters_pca.Rd @@ -17,7 +17,10 @@ \arguments{ \item{x}{An object.} -\item{type}{Character vector, indicating the type of plot.} +\item{type}{Character vector, indicating the type of plot. +Options are three different shapes to represent component loadings; +\code{"bar"} (default) for a horizontal bar chart, or +\code{"line"} for a horizontal point and line chart.} \item{size_text}{Numeric value specifying size of text labels.} diff --git a/tests/testthat/_snaps/plot.check_normality/check-normality-works-lm-pp.svg b/tests/testthat/_snaps/plot.check_normality/check-normality-works-lm-pp.svg index 2b77bf184..534fa12ce 100644 --- a/tests/testthat/_snaps/plot.check_normality/check-normality-works-lm-pp.svg +++ b/tests/testthat/_snaps/plot.check_normality/check-normality-works-lm-pp.svg @@ -9,7 +9,7 @@ stroke-linejoin: round; stroke-miterlimit: 10.00; } - ]]> + ]]>qq @@ -95,9 +95,9 @@ 0.50 0.75 1.00 -Probability Points -Cummulative Probability +Standard Normal Cumulative Probability +Sample Cummulative Probability Dots should fall along the line -Normality of Residuals (PP plot) +Normality of Residuals