This function creates a normal Q-Q plot for a given numeric vector and adds confidence bands to visualize the variability of the quantiles.
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,
...
)
A Q-Q plot is created and the function returns this as a recordedplot
.
A numeric vector of data values.
A character string specifying the title of the histogram. Default is "Histogram with Normal Curve".
A character string specifying the y-axsis label. Default name is "Quantiles of: data_name"
.
Numeric, between 0 and 1. Confidence level for the confidence bands. Default is 0.95 (95% confidence).
Numeric, optional parameter for color of point with default 'black'.
Numeric, optional parameter shape of points default pch = 19
.
Numeric, optional parameter for graph cex with default cex = 0.6
.
A logical value default FALSE
, if TRUE
a png file is saved under the name of the data of under the specified file name.
Logical. If TRUE
, opens generated png files.
Character string specifying the name of the output file (without extension). Default is the name of the vector or dataframe followed by "_histogram.png".
Character string specifying the name of the directory of the output file. Default is tempdir()
. If the output_file
already contains a directory name output_dir
can be omitted, if used it overwrites the dir specified in output_file
.
Logical. If TRUE
, saves the file in the working directory Default is FALSE
, to avoid unintended changes to the global environment. If the output_dir
is specified save_in_wdir
is overwritten with output_dir
.
Numeric, png figure width default 8
inch.
Numeric, png figure height default 7
inch.
Numeric, png figure units default inch.
Numeric, png figure resolution default 300
dpi.
Additional graphical parameters to be passed to the qqnorm
function.
Sander H. van Delden plantmind@proton.me
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
.
# 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")
Run the code above in your browser using DataLab