f_qqnorm {rfriend} | R Documentation |
Normal Q-Q Plot with Confidence Bands
Description
This function creates a normal Q-Q plot for a given numeric vector and adds confidence bands to visualize the variability of the quantiles.
Usage
f_qqnorm(
x,
main = NULL,
ylab = NULL,
conf_level = 0.95,
col = NULL,
pch = NULL,
cex = NULL,
save_png = FALSE,
open_png = TRUE,
output_file = NULL,
output_dir = NULL,
save_in_wdir = FALSE,
width = 8,
height = 7,
units = "in",
res = 300,
...
)
Arguments
x |
A numeric vector of data values. |
main |
A character string specifying the title of the histogram. Default is "Histogram with Normal Curve". |
ylab |
A character string specifying the y-axsis label. Default name is |
conf_level |
Numeric, between 0 and 1. Confidence level for the confidence bands. Default is 0.95 (95% confidence). |
col |
Numeric, optional parameter for color of point with default 'black'. |
pch |
Numeric, optional parameter shape of points default |
cex |
Numeric, optional parameter for graph cex with default |
save_png |
A logical value default |
open_png |
Logical. If |
output_file |
Character string specifying the name of the output file (without extension). Default is the name of the vector or dataframe followed by "_histogram.png". |
output_dir |
Character string specifying the name of the directory of the output file. Default is |
save_in_wdir |
Logical. If |
width |
Numeric, png figure width default |
height |
Numeric, png figure height default |
units |
Numeric, png figure units default inch. |
res |
Numeric, png figure resolution default |
... |
Additional graphical parameters to be passed to the |
Details
The function calculates theoretical quantiles for a normal distribution and compares them with the sample quantiles of the input data.
It also computes confidence intervals for the order statistics using the Blom approximation and displays these intervals as shaded bands on the plot.
The reference line is fitted based on the first and third quartiles of both the sample data and theoretical quantiles.
To increase resolution you can use png(...,res = 600)
or the 'RStudio' chunck setting, e.g. dpi = 600
.
Value
A Q-Q plot is created and the function returns this as a recordedplot
.
Author(s)
Sander H. van Delden plantmind@proton.me
Examples
# Generate random normal data
set.seed(123)
data <- rnorm(100)
# Create a Q-Q plot with confidence bands
f_qqnorm(data)
# Customize the plot with additional graphical parameters
f_qqnorm(data, conf_level = 0.99, pch = 16, col = "blue")