# ------------------------------------------------ # Program: Univariate3.R # Author: Steven M. Boker # Date: Tue Sep 25 10:48:33 EDT 2007 # # Provides examples of the use of QQ plots for the # visualization of univariate distributions # # ------------------------------------------------ library(lattice) # ------------------------------------------------ # Read the iris data. iris <- data.frame(read.table("iris.dat", header=T)) summary(iris) dim(iris) # ------------------------------------------------ # Quantile plot of sepal length using the "plot" command. pdf("Uni3Qplot1.pdf", height=5, width=5) tLength <- length(iris$sepal.length) plot(c(1:tLength)/tLength, sort(iris$sepal.length), xlab = "Fraction Value", ylab="Sepal Length (cm)") dev.off() # ------------------------------------------------ # Quantile plot of sepal length using Trellis graphics pdf("Uni3Qplot2.pdf", height=5, width=5) print(qqmath(~ sepal.length, distribution=qunif, data=iris, aspect=1, xlab = list(label="Fraction Value",cex=1.25), ylab=list(label="Sepal Length (cm)",cex=1.25), scales=list(cex=1.25), main=list(label="Quantiles of Sepal Length",cex=1.25) )) dev.off() # ------------------------------------------------ # Quantile plot of sepal length conditioned by variety pdf("Uni3Qplot3.pdf", height=4,width=7.5) print(qqmath(~ sepal.length | variety, distribution=qunif, data=iris, panel = function(x, ...) { panel.qqmathline(x, ...) panel.qqmath(x, ...) }, layout=c(3,1), aspect=1, xlab = list(label="Fraction Value",cex=1.25), ylab=list(label="Sepal Length (cm)",cex=1.25), scales=list(cex=1.25), main=list(label="Quantiles of Sepal Length",cex=1.25) )) dev.off() # ------------------------------------------------ # Quantile-Normal plot of sepal length against normal distribution pdf("UniQQnorm1.pdf", height=5, width=5) qqnorm(iris$sepal.length, xlab = "Quantiles from Normal Distribution", ylab = "Quantiles from Sample") dev.off() # ------------------------------------------------ # Quantile-Quantile plot of sepal.length against normal distribution pdf("UniQQnorm2.pdf", height=5, width=5) print(qqmath(~ sepal.length, distribution=qnorm, data=iris, prepanel = prepanel.qqmathline, panel = function(x, ...) { panel.qqmathline(x, ...) panel.qqmath(x, ...) }, aspect=1, xlab = list(label="Normal Distribution",cex=1.25), ylab=list(label="Sepal Length (cm)",cex=1.25), scales=list(cex=1.25), main=list(label="Quantiles of Sepal Length",cex=1.25) )) dev.off() # ------------------------------------------------ # Quantile-Quantile plot of sepal.length against normal distribution # by the conditioning variable variety. pdf("UniQQnorm3.pdf", height=5, width=5) print(qqmath(~ sepal.length | variety, distribution=qnorm, data=iris, prepanel = prepanel.qqmathline, panel = function(x, ...) { panel.qqmathline(x, ...) panel.qqmath(x, ...) }, aspect=1,layout=c(2,2), xlab = list(label="Normal Distribution",cex=1.25), ylab=list(label="Sepal Length (cm)",cex=1.25), scales=list(cex=1.25), main=list(label="Quantiles of Sepal Length",cex=1.25) )) dev.off() # ------------------------------------------------ # Quantile-Quantile plot of sepal.length of Setosa versus Versicolor pdf("UniQQIris1.pdf", height=5, width=5) print(qq(variety ~ sepal.length, data=iris, subset=variety=="Setosa" | variety=="Versicolor", aspect=1, xlab = list(label="Versacolor",cex=1.25), ylab=list(label="Setosa",cex=1.25), scales=list(cex=1.25), main=list(label="Quantiles of Setosa vs Versacolor",cex=1.25))) dev.off()