### Install development version from GitHub with devtools Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Installs the development version of qqplotr from GitHub using devtools. The first line is commented out to avoid reinstalling devtools if already installed. ```r # install.packages("devtools") library(devtools) devtools::install_github("aloy/qqplotr") ``` -------------------------------- ### Devel Installation Log Source: https://github.com/aloy/qqplotr/blob/master/revdep/failures.md Full installation log for the development environment. The compilation succeeds, but linking fails because the library 'emutls_w' is not found and the gfortran search paths are missing, causing the linker to exit with code 1. ```text * installing *source* package ‘ARCensReg’ ... ** this is package ‘ARCensReg’ version ‘3.0.1’ ** package ‘ARCensReg’ successfully unpacked and MD5 sums checked ** using staged installation ** libs using C++ compiler: ‘Apple clang version 17.0.0 (clang-1700.0.13.5)’ using SDK: ‘MacOSX15.5.sdk’ clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/RcppArmadillo/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/Rcpp/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c Functions_Rcpp.cpp -o Functions_Rcpp.o clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/RcppArmadillo/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/Rcpp/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o ARCensReg.so Functions_Rcpp.o RcppExports.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/14.2.0 -L/opt/gfortran/lib -lemutls_w -lheapt_w -lgfortran -lquadmath -F/Library/Frameworks/R.framework/.. -framework R ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/14.2.0' not found ld: warning: search path '/opt/gfortran/lib' not found ld: library 'emutls_w' not found clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [ARCensReg.so] Error 1 ERROR: compilation failed for package ‘ARCensReg’ * removing ‘/Users/aloy/Documents/r-packages/qqplotr/revdep/checks.noindex/ARCensReg/new/ARCensReg.Rcheck/ARCensReg’ ``` -------------------------------- ### QQPlot example with multiple bands (fails with gg_par not found) Source: https://github.com/aloy/qqplotr/blob/master/revdep/problems.md Example from the QQPlot documentation that triggers an error during R CMD check. The call to QQPlot with multiple band specifications fails because the internal function gg_par is not found, causing the example to halt. ```r set.seed(8525) ... QQPlot(data, val = "norm", band = list( list(bandType = "ks", mapping = ggplot2::aes(fill = "KS"), alpha = 0.3), list(bandType = "ts", mapping = ggplot2::aes(fill = "TS")), list(bandType = "pointwise", mapping = ggplot2::aes(fill = "Normal")), list(bandType = "boot", mapping = ggplot2::aes(fill = "Bootstrap")) ), band_alpha = 0.6) ``` -------------------------------- ### CRAN Installation Log Source: https://github.com/aloy/qqplotr/blob/master/revdep/failures.md Full installation log for the CRAN environment. The compilation succeeds, but linking fails because the library 'emutls_w' is not found and the gfortran search paths are missing, causing the linker to exit with code 1. ```text * installing *source* package ‘ARCensReg’ ... ** this is package ‘ARCensReg’ version ‘3.0.1’ ** package ‘ARCensReg’ successfully unpacked and MD5 sums checked ** using staged installation ** libs using C++ compiler: ‘Apple clang version 17.0.0 (clang-1700.0.13.5)’ using SDK: ‘MacOSX15.5.sdk’ clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/RcppArmadillo/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/Rcpp/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c Functions_Rcpp.cpp -o Functions_Rcpp.o clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/RcppArmadillo/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/ARCensReg/Rcpp/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o ARCensReg.so Functions_Rcpp.o RcppExports.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/14.2.0 -L/opt/gfortran/lib -lemutls_w -lheapt_w -lgfortran -lquadmath -F/Library/Frameworks/R.framework/.. -framework R ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/14.2.0' not found ld: warning: search path '/opt/gfortran/lib' not found ld: library 'emutls_w' not found clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [ARCensReg.so] Error 1 ERROR: compilation failed for package ‘ARCensReg’ * removing ‘/Users/aloy/Documents/r-packages/qqplotr/revdep/checks.noindex/ARCensReg/old/ARCensReg.Rcheck/ARCensReg’ ``` -------------------------------- ### Install stable CRAN version Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Installs the stable version of qqplotr from CRAN. ```r install.packages("qqplotr") ``` -------------------------------- ### stat_qq_line examples: normal, exponential, and detrended Q-Q plots Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_qq_line.html Shows three Q-Q plot examples using stat_qq_line() and stat_qq_point(): a normal Q-Q plot on random normal data, an exponential Q-Q plot on the airquality Ozone data with rate=1, and a detrended exponential Q-Q plot with detrend=TRUE. Each example builds a ggplot object and prints it with gg. ```r # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal Q-Q plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg # Exponential Q-Q plot of mean ozone levels (airquality dataset) di <- "exp" dp <- list(rate = 1) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_line(distribution = di, dparams = dp) + stat_qq_point(distribution = di, dparams = dp) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg # Detrended Exponential Q-Q plot of mean ozone levels di <- "exp" dp <- list(rate = 1) de <- TRUE gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_line(distribution = di, detrend = de) + stat_qq_point(distribution = di, detrend = de) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Examples: Normal P-P plot, shifted Normal, and airquality Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_pp_point.html Three examples: generating random normal data and creating a normal P-P plot, creating a shifted normal P-P plot with dparams, and creating a normal P-P plot of mean ozone levels from the airquality dataset. ```r # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal P-P plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_point() + labs(x = "Probability Points", y = "Cumulative Probability") gg # Shifted Normal P-P plot of Normal data dp <- list(mean = 1.5) gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg # Normal P-P plot of mean ozone levels (airquality dataset) dp <- list(mean = 38, sd = 27) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` -------------------------------- ### Run Shiny App with runShinyExample() Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Launches the interactive Shiny app included in the qqplotr package for exploring its functions and parameters. Call this function in an R session to start the app. ```r runShinyExample() ``` -------------------------------- ### HLMdiag installation failure log Source: https://github.com/aloy/qqplotr/blob/master/revdep/failures.md Installation log showing the compilation of HLMdiag 0.5.1, which fails at the linking stage because the 'emutls_w' library is not found, causing the package compilation to fail. ```text * installing *source* package ‘HLMdiag’ ... ** this is package ‘HLMdiag’ version ‘0.5.1’ ** package ‘HLMdiag’ successfully unpacked and MD5 sums checked ** using staged installation ** libs using C compiler: ‘Apple clang version 17.0.0 (clang-1700.0.13.5)’ using C++ compiler: ‘Apple clang version 17.0.0 (clang-1700.0.13.5)’ using SDK: ‘MacOSX15.5.sdk’ clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/Rcpp/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/RcppArmadillo/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c HLMdiag_init.c -o HLMdiag_init.o clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/Rcpp/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/RcppArmadillo/include' -I/opt/R/arm64/include -DARMA_64BIT_WORD=1 -fPIC -falign-functions=64 -Wall -g -O2 -c cooksd_obs.cpp -o cooksd_obs.o ... clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/Rcpp/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/RcppArmadillo/include' -I/opt/R/arm64/include -DARMA_64BIT_WORD=1 -fPIC -falign-functions=64 -Wall -g -O2 -c linear_algebra_fnc.cpp -o linear_algebra_fnc.o clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/Rcpp/include' -I'/Users/aloy/Documents/r-packages/qqplotr/revdep/library.noindex/HLMdiag/RcppArmadillo/include' -I/opt/R/arm64/include -DARMA_64BIT_WORD=1 -fPIC -falign-functions=64 -Wall -g -O2 -c mdffits_subset.cpp -o mdffits_subset.o clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o HLMdiag.so HLMdiag_init.o cooksd_obs.o cooksd_subset.o covratio.o covtrace.o linear_algebra_fnc.o mdffits_subset.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/14.2.0 -L/opt/gfortran/lib -lemutls_w -lheapt_w -lgfortran -lquadmath -F/Library/Frameworks/R.framework/.. -framework R ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/14.2.0' not found ld: warning: search path '/opt/gfortran/lib' not found ld: library 'emutls_w' not found clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [HLMdiag.so] Error 1 ERROR: compilation failed for package ‘HLMdiag’ * removing ‘/Users/aloy/Documents/r-packages/qqplotr/revdep/checks.noindex/HLMdiag/new/HLMdiag.Rcheck/HLMdiag’ ``` -------------------------------- ### Create P-P plots with stat_pp_band(), stat_pp_line(), and stat_pp_point() Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_pp_band.html Shows how to create P-P plots with stat_pp_band(), stat_pp_line(), and stat_pp_point() from the qqplotr package. The examples cover default Normal P-P plots, shifted Normal with dparams, Exponential with distribution = "exp", and a Normal fit to the airquality Ozone data with dparams = list(mean = 38, sd = 27). Each plot is stored in gg and printed with gg. ```R # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100), exp = rexp(100)) # Normal P-P plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_band() + stat_pp_line() + stat_pp_point() + labs(x = "Probability Points", y = "Cumulative Probability") gg # Shifted Normal P-P plot of Normal data dp <- list(mean = 1.5) gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_band(dparams = dp) + stat_pp_line() + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg # Exponential P-P plot of Exponential data di <- "exp" gg <- ggplot(data = smp, mapping = aes(sample = exp)) + stat_pp_band(distribution = di) + stat_pp_line() + stat_pp_point(distribution = di) + labs(x = "Probability Points", y = "Cumulative Probability") gg # Normal P-P plot of mean ozone levels (airquality dataset) dp <- list(mean = 38, sd = 27) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_pp_band(dparams = dp) + stat_pp_line() + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` -------------------------------- ### Examples of stat_pp_line with stat_pp_point Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_pp_line.html Three examples of creating P-P plots with stat_pp_line and stat_pp_point. The first uses random normal data, the second shifts the distribution with dparams = list(mean = 1.5), and the third uses the airquality Ozone data with dparams = list(mean = 38, sd = 27). ```r # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal P-P plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_line() + stat_pp_point() + labs(x = "Probability Points", y = "Cumulative Probability") gg # Shifted Normal P-P plot of Normal data dp <- list(mean = 1.5) gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_line() + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg # Normal P-P plot of mean ozone levels (airquality dataset) dp <- list(mean = 38, sd = 27) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_pp_line() + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` -------------------------------- ### Installation Error Message Source: https://github.com/aloy/qqplotr/blob/master/revdep/failures.md Error message shown when checking whether the ARCensReg package can be installed. The installation fails, and the details are written to the specified log file. ```text Installation failed. See ‘/Users/aloy/Documents/r-packages/qqplotr/revdep/checks.noindex/ARCensReg/new/ARCensReg.Rcheck/00install.out’ for details. ``` -------------------------------- ### HLMdiag installation error message Source: https://github.com/aloy/qqplotr/blob/master/revdep/failures.md Error message indicating that the HLMdiag package installation failed, with a path to the installation log file for details. ```text Installation failed. See ‘/Users/aloy/Documents/r-packages/qqplotr/revdep/checks.noindex/HLMdiag/new/HLMdiag.Rcheck/00install.out’ for details. ``` -------------------------------- ### Generate Normal and Exponential Q-Q Plots with stat_qq_point Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_qq_point.html This example shows how to create a normal Q-Q plot from simulated normal data and an exponential Q-Q plot using the airquality dataset. It uses stat_qq_point with optional distribution and dparams arguments to specify the theoretical distribution. ```R # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal Q-Q plot of simulated Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg # Exponential Q-Q plot of mean ozone levels (airquality dataset) di <- "exp" dp <- list(rate = 1) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_point(distribution = di, dparams = dp) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Create a P-P plot with qqplotr Source: https://github.com/aloy/qqplotr/blob/master/revdep/library.noindex/qqplotr/old/qqplotr/doc/introduction.html Use qqplotr to generate a P-P plot. The example shows the basic usage of the package's plotting functions. ```R gg ``` -------------------------------- ### Get HLMdiag reverse dependency details Source: https://github.com/aloy/qqplotr/blob/master/revdep/failures.md Run this command to get more information about the HLMdiag package's reverse dependency check details. ```R revdepcheck::revdep_details(, "HLMdiag") ``` -------------------------------- ### Normal Q-Q plot with tail-sensitive bands Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_band.Rd Creates a normal Q-Q plot with tail-sensitive confidence bands for the norm variable in the smp dataset. This example is wrapped in \dontrun{} and is not executed during package checks. ```R gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band(bandType = "ts") + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Normal Q-Q plot with bootstrap bands Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_band.Rd Creates a normal Q-Q plot with bootstrap confidence bands for the norm variable in the smp dataset. This example is wrapped in \dontrun{} and is not executed during package checks. ```R gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band(bandType = "boot") + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### stat_pp_point Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_pp_point.html Documentation for the stat_pp_point function from the qqplotr package, including usage, arguments, and examples. ```APIDOC ## stat_pp_point ### Description Draws probability-probability points. ### Usage ```r stat_pp_point( mapping = NULL, data = NULL, geom = "point", position = "identity", na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, distribution = "norm", dparams = list(), detrend = FALSE, ... ) ``` ### Arguments - **mapping** (aes) - Optional - Set of aesthetic mappings created by `aes()` or `aes_()`. If specified and `inherit.aes = TRUE` (the default), it is combined with the default mapping at the top level of the plot. You must supply `mapping` if there is no plot mapping. - **data** (data.frame, function, or NULL) - Optional - The data to be displayed in this layer. If `NULL`, the default, the data is inherited from the plot data as specified in the call to `ggplot()`. A `data.frame`, or other object, will override the plot data. All objects will be fortified to produce a data frame. A `function` will be called with a single argument, the plot data. The return value must be a `data.frame`, and will be used as the layer data. - **geom** (character) - Optional - The geometric object to use display the data. - **position** (character or position adjustment) - Optional - Position adjustment, either as a string, or the result of a call to a position adjustment function. - **na.rm** (logical) - Optional - If `FALSE`, the default, missing values are removed with a warning. If `TRUE`, missing values are silently removed. - **show.legend** (logical) - Optional - Should this layer be included in the legends? `NA`, the default, includes if any aesthetics are mapped. `FALSE` never includes, and `TRUE` always includes. It can also be a named logical vector to finely select the aesthetics to display. - **inherit.aes** (logical) - Optional - If `FALSE`, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification. - **distribution** (character) - Optional - Theoretical probability distribution function to use. Do not provide the full distribution function name (e.g., `"dnorm"`). Instead, just provide its shortened name (e.g., `"norm"`). If you wish to provide a custom distribution, you may do so by first creating the density, quantile, and random functions following the standard nomenclature from the `stats` package (i.e., for `"custom"`, create the `dcustom`, `pcustom`, `qcustom`, and `rcustom` functions). - **dparams** (list) - Optional - List of additional parameters passed on to the previously chosen `distribution` function. If an empty list is provided (default) then the distributional parameters are estimated via MLE. MLE for custom distributions is currently not supported, so you must provide the appropriate `dparams` in that case. - **detrend** (logical) - Optional - Should the plot objects be detrended? If `TRUE`, the objects will be detrended according to the default identity P-P line. This procedure was described by Thode (2002), and may help reducing visual bias caused by the orthogonal distances from P-P points to the reference line. - **...** - Optional - Other arguments passed on to `layer()`. These are often aesthetics, used to set an aesthetic to a fixed value, like `colour = "red"` or `size = 3`. They may also be parameters to the paired geom/stat. ### Examples ```r # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal P-P plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_point() + labs(x = "Probability Points", y = "Cumulative Probability") gg # Shifted Normal P-P plot of Normal data dp <- list(mean = 1.5) gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg # Normal P-P plot of mean ozone levels (airquality dataset) dp <- list(mean = 38, sd = 27) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` ``` -------------------------------- ### Load qqplotr package Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Loads the qqplotr package before creating Q-Q plots. ```r require(qqplotr) ``` -------------------------------- ### Create Q-Q plots with stat_qq_band for various distributions and band types Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_qq_band.html Shows how to create Q-Q plots with confidence bands using stat_qq_band, stat_qq_line, and stat_qq_point. Covers normal, exponential, detrended exponential, bootstrap, and tail-sensitive band types. Requires the ggplot2 and qqplotr packages. ```R # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal Q-Q plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band() + stat_qq_line() + stat_qq_point() gg + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") # Exponential Q-Q plot of mean ozone levels (airquality dataset) di <- "exp" dp <- list(rate = 1) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_band(distribution = di, dparams = dp) + stat_qq_line(distribution = di, dparams = dp) + stat_qq_point(distribution = di, dparams = dp) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg # Detrended Exponential Q-Q plot of mean ozone levels di <- "exp" dp <- list(rate = 1) de <- TRUE gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_band(distribution = di, detrend = de) + stat_qq_line(distribution = di, detrend = de) + stat_qq_point(distribution = di, detrend = de) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg # Normal Q-Q plot of Normal data with boostrap confidence bands bt <- "boot" gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band(bandType = bt) + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg # Normal Q-Q plot of Normal data with tail-sensitive confidence bands bt <- "ts" gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band(bandType = bt) + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Basic P-P plot with stat_pp_band, stat_pp_line, and stat_pp_point Source: https://github.com/aloy/qqplotr/blob/master/docs/articles/introduction.html Creates a P-P plot for the simulated normal data against the standard normal distribution using the qqplotr package. The plot includes confidence bands, a reference line, and points. ```R gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_band() + stat_pp_line() + stat_pp_point() + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` -------------------------------- ### Create default Q-Q plot with stat_qq_* Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Constructs a default Q-Q plot with Normal confidence bands using the stat_qq_* functions. All points lie within the bands for the simulated data. ```r gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band() + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Create Normal Q-Q plot with stat_qq_band() Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_band.Rd Creates a Normal Q-Q plot with default confidence bands and then a second plot using bandType = "ell" for equal local levels bands. Requires ggplot2 and the qqplotr package. ```R # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal Q-Q plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band() + stat_qq_line() + stat_qq_point() gg + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") # Normal Q-Q plot of Normal data with equal local levels (ell) bands gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_band(bandType = "ell") + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Q-Q plot with Exponential distribution and dparams Source: https://github.com/aloy/qqplotr/blob/master/docs/articles/introduction.html Builds a Q-Q plot for the Ozone variable from the airquality dataset using an Exponential theoretical distribution. The distribution parameter is set to "exp" and the rate parameter is passed via dparams. Note that distributional parameters mainly affect the x-axis range in Q-Q plots. ```r di <- "exp" # exponential distribution dp <- list(rate = 2) # exponential rate parameter gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_band(distribution = di, dparams = dp) + stat_qq_line(distribution = di, dparams = dp) + stat_qq_point(distribution = di, dparams = dp) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Q-Q plot with custom distribution and dparams Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Builds a Q-Q plot for the airquality Ozone data using an Exponential distribution with rate=2. Distributional parameters mainly affect the x-axis range in Q-Q plots. ```r di <- "exp" # exponential distribution dp <- list(rate = 2) # exponential rate parameter gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_band(distribution = di, dparams = dp) + stat_qq_line(distribution = di, dparams = dp) + stat_qq_point(distribution = di, dparams = dp) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Exponential Q-Q plot with distribution and dparams Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_line.Rd Creates an Exponential Q-Q plot for the Ozone column of the airquality dataset. Specifies the exponential distribution with rate parameter 1 via dparams. ```r # Exponential Q-Q plot of mean ozone levels (airquality dataset) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_line(distribution = "exp", dparams = list(rate = 1)) + stat_qq_point(distribution = "exp", dparams = list(rate = 1)) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Normal Q-Q plot with stat_qq_line() Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_line.Rd Creates a Normal Q-Q plot using stat_qq_line() and stat_qq_point() on random Normal data. Sets a seed for reproducibility and uses the default Normal distribution. ```r # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal Q-Q plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Create detrended P-P plot with Exponential distribution Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Creates a detrended P-P plot for the mean ozone levels from the `airquality` dataset using an Exponential distribution. The `rate` parameter is set to .022 based on empirical tests to keep most points inside the confidence bands; points outside at the lower tail indicate a more appropriate distribution should be selected. ```r di <- "exp" dp <- list(rate = .022) # value is based on some empirical tests de <- TRUE gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_pp_band(distribution = di, detrend = de, dparams = dp) + stat_pp_line(detrend = de) + stat_pp_point(distribution = di, detrend = de, dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") + scale_y_continuous(limits = c(-.5, .5)) gg ``` -------------------------------- ### Simulate standard Normal data Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Simulates 100 samples from a standard Normal distribution and stores them in a data frame for plotting. ```r set.seed(0) smp <- data.frame(norm = rnorm(100)) ``` -------------------------------- ### Exponential Q-Q plot with stat_qq_band Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_band.Rd Creates an exponential Q-Q plot for the Ozone variable in the airquality dataset, using rate = 1 for the exponential distribution. The plot includes the confidence band, line, and points, with labeled axes. ```R gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_band(distribution = "exp", dparams = list(rate = 1)) + stat_qq_line(distribution = "exp", dparams = list(rate = 1)) + stat_qq_point(distribution = "exp", dparams = list(rate = 1)) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Normal P-P plot of airquality Ozone with dparams Source: https://github.com/aloy/qqplotr/blob/master/man/stat_pp_line.Rd Creates a Normal P-P plot for the Ozone variable from the airquality dataset, using dparams with mean = 38 and sd = 27. ```r # Normal P-P plot of mean ozone levels (airquality dataset) dp <- list(mean = 38, sd = 27) gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_pp_line() + stat_pp_point(dparams = dp) + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` -------------------------------- ### Detrended Exponential Q-Q plot with detrend = TRUE Source: https://github.com/aloy/qqplotr/blob/master/man/stat_qq_line.Rd Creates a detrended Exponential Q-Q plot for the Ozone column of the airquality dataset. Uses detrend = TRUE to remove the trend from the plot. ```r # Detrended Exponential Q-Q plot of mean ozone levels gg <- ggplot(data = airquality, mapping = aes(sample = Ozone)) + stat_qq_line(distribution = "exp", detrend = TRUE) + stat_qq_point(distribution = "exp", detrend = TRUE) + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") gg ``` -------------------------------- ### Load longjump dataset Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/longjump.html Loads the longjump dataset from the qqplotr package. The dataset contains 42 observations on 4 variables: rank, name, country, and distance. ```r data(longjump) ``` -------------------------------- ### Normal P-P plot with stat_pp_line() and stat_pp_point() Source: https://github.com/aloy/qqplotr/blob/master/man/stat_pp_line.Rd Creates a Normal P-P plot for random Normal data using stat_pp_line() and stat_pp_point(). The data is generated with set.seed(0) and rnorm(100). ```r # generate random Normal data set.seed(0) smp <- data.frame(norm = rnorm(100)) # Normal P-P plot of Normal data gg <- ggplot(data = smp, mapping = aes(sample = norm)) + stat_pp_line() + stat_pp_point() + labs(x = "Probability Points", y = "Cumulative Probability") gg ``` -------------------------------- ### stat_qq_line Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_qq_line.html Documentation for the stat_qq_line function from the qqplotr package, which draws a quantile-quantile line with an optional detrending option. ```APIDOC ## stat_qq_line ### Description Draws a quantile-quantile line, with an additional detrend option. ### Usage ```r stat_qq_line( mapping = NULL, data = NULL, geom = "path", position = "identity", na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, distribution = "norm", dparams = list(), detrend = FALSE, identity = FALSE, qtype = 7, qprobs = c(0.25, 0.75), ... ) ``` ### Arguments - **mapping** (aesthetic mapping) - Optional - Set of aesthetic mappings created by `aes()` or `aes_()`. If specified and `inherit.aes = TRUE` (the default), it is combined with the default mapping at the top level of the plot. You must supply `mapping` if there is no plot mapping. - **data** (data.frame, function, or NULL) - Optional - The data to be displayed in this layer. If `NULL`, the default, the data is inherited from the plot data as specified in the call to `ggplot()`. A `data.frame`, or other object, will override the plot data. All objects will be fortified to produce a data frame. A `function` will be called with a single argument, the plot data. The return value must be a `data.frame`, and will be used as the layer data. A `function` can be created from a `formula` (e.g. `~ head(.x, 10)`). - **geom** (character) - Optional - The geometric object to use display the data. - **position** (character or position adjustment function) - Optional - Position adjustment, either as a string, or the result of a call to a position adjustment function. - **na.rm** (logical) - Optional - If `FALSE`, the default, missing values are removed with a warning. If `TRUE`, missing values are silently removed. - **show.legend** (logical or named logical vector) - Optional - Should this layer be included in the legends? `NA`, the default, includes if any aesthetics are mapped. `FALSE` never includes, and `TRUE` always includes. It can also be a named logical vector to finely select the aesthetics to display. - **inherit.aes** (logical) - Optional - If `FALSE`, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification. - **distribution** (character) - Optional - Theoretical probability distribution function to use. Do not provide the full distribution function name (e.g., `"dnorm"`). Instead, just provide its shortened name (e.g., `"norm"`). If you wish to provide a custom distribution, you may do so by first creating the density, quantile, and random functions following the standard nomenclature from the `stats` package (i.e., for `"custom"`, create the `dcustom`, `pcustom`, `qcustom`, and `rcustom` functions). - **dparams** (list) - Optional - List of additional parameters passed on to the previously chosen `distribution` function. If an empty list is provided (default) then the distributional parameters are estimated via MLE. MLE for custom distributions is currently not supported, so you must provide the appropriate `dparams` in that case. - **detrend** (logical) - Optional - Should the plot objects be detrended? If `TRUE`, 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. - **identity** (logical) - Optional - Should an identity line be used as the reference line? If `TRUE`, the identity line is used. If `FALSE` (default), the commonly-used Q-Q line that intercepts two data quantiles specified in `qprobs` is used. Please notice that the chosen reference line will also be used for the detrending procedure, if `detrend = TRUE`. - **qtype** (integer) - Optional - Integer between 1 and 9. Only used if `detrend = TRUE` and `identity = FALSE`. Type of the quantile algorithm to be used by the `quantile` function to construct the Q-Q line. - **qprobs** (numeric vector) - Optional - Numeric vector of length two. Only used if `detrend = TRUE` and `identity = FALSE`. Represents the quantiles used by the `quantile` function to construct the Q-Q line. - **...** (other arguments) - Optional - Other arguments passed on to `layer()`. These are often aesthetics, used to set an aesthetic to a fixed value, like `colour = "red"` or `size = 3`. They may also be parameters to the paired geom/stat. ``` -------------------------------- ### stat_pp_point function signature Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/stat_pp_point.html The function signature for stat_pp_point, showing its default arguments including mapping, data, geom, position, na.rm, show.legend, inherit.aes, distribution, dparams, detrend, and ... ```r stat_pp_point( mapping = NULL, data = NULL, geom = "point", position = "identity", na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, distribution = "norm", dparams = list(), detrend = FALSE, ... ) ``` -------------------------------- ### Q-Q plot with multiple band types using geom_qq_band Source: https://github.com/aloy/qqplotr/blob/master/README.Rmd Creates a Q-Q plot with four different confidence band types (KS, TS, pointwise, bootstrap) using geom_qq_band, which allows more flexibility with graphical parameters. ```r gg <- ggplot(data = smp, mapping = aes(sample = norm)) + geom_qq_band(bandType = "ks", mapping = aes(fill = "KS"), alpha = 0.5) + geom_qq_band(bandType = "ts", mapping = aes(fill = "TS"), alpha = 0.5) + geom_qq_band(bandType = "pointwise", mapping = aes(fill = "Normal"), alpha = 0.5) + geom_qq_band(bandType = "boot", mapping = aes(fill = "Bootstrap"), alpha = 0.5) + stat_qq_line() + stat_qq_point() + labs(x = "Theoretical Quantiles", y = "Sample Quantiles") + scale_fill_discrete("Bandtype") gg ``` -------------------------------- ### Load the iowa dataset Source: https://github.com/aloy/qqplotr/blob/master/docs/reference/iowa.html Loads the 2012 BRFSS sample for the state of Iowa into the R environment. The dataset is a data frame with 7166 observations on 3 variables: SEX, WTKG3, and HTIN4. ```r data(iowa) ```