Section 17 One Numeric: qqnorm

17.1 QQ plot

The function qqnorm is a generic function the default method of which produces a normal QQ plot of the data values. The function qqline adds a line to a theoretical normal, quantile-quantile plot.

The function qqplot producess a QQ plot of two datasets. The function can be used to draw QQ plot for the observed data and theoretical quantile distributions.

17.2 Example 1

data(iris)

?qqnorm

x <- iris$Sepal.Length
str(x)
 num [1:150] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
qqnorm(x)
qqline(x)

qqnorm(x, main='Normal QQ of Sepal Length',
     xlab='Theoretical Quantiles',
     ylab='Sepal Length (cm)',
     col='blue')
qqline(x, lty=1, lwd=2, col='red')

qqplot(x=rnorm(1000, mean=mean(x), sd=sd(x)), y=x)

qqplot(x=rnorm(1000, mean=0, sd=1), y=x)
qqline(x)

17.3 Example 2

data(warpbreaks)

  • Draw a QQ plot of the variable breaks

  • Discuss the QQ plot

  • Transform the data using log-transformation and redraw the QQ plot