Learn R Programming

Ecfun (version 0.1-4)

qqnorm2: Normal Probability Plot with Multiple Symbols

Description

Create a normal probability plot with different symbols for the values of another variable. qqnorm2 produces an object of class qqnorm2, whose plot method produces the plot.

Usage

qqnorm2(y, z, plot.it=TRUE, datax=TRUE, pch=NULL, ...)
## S3 method for class 'qqnorm2':
plot(x, y, ...)
## S3 method for class 'qqnorm2':
lines(x, ...)
## S3 method for class 'qqnorm2':
points(x, ...)

Arguments

y
For qnorm2, y is a numeric vector for which a normal probability plot is desired. For plot.qqnorm2, y is ignored; it is included, because the generic
z
A variable to indicate different plotting symbols.
plot.it
logical: Should the result be plotted?
datax
The datax argument of qqnorm: If TRUE, the data are displayed on the horizontal rather than the vertical axis. (The default value for datax is the opposite of that for
x
an object of class qqnorm2.
pch
a named vector of the plotting symbols to be used with names corresponding to the levels of z. By default, if z takes levels FALSE and TRUE (or 0 and 1), pch=c(4, 1) to plot a "x" for FALS
...
Optional arguments. For plot.qqnorm2, they are passed to plot. For qqnorm2, they are passed to qqnorm and to plot.qqnorm2.

Value

  • qqnorm2 returns a list with components, x, y, z, and pch.

Details

For qqnorm2: 1. q2 <- qqnorm(y, datax=datax, ...) 2. q2[["z"]] <- z 3. q2[["pch"]] gets whatever pch decodes to. 4. Silently return(list(x, y, z, pch)), where "x" and "y" are as returned by qqnorm in step 1 above. For plot.qqnorm2, plot(x, y, pch=pch[z], ...). For lines.qqnorm2, lines(x, y, pch=pch[z], ...). For points.qqnorm2, points(x, y, pch=pch[z], ...).

See Also

qqnorm, qqnorm2s, plot points lines

Examples

Run this code
##
## a simple test data.frame to illustrate the plot
## but too small to illustrate qqnorm concepts
##
tstDF <- data.frame(y=1:3, z1=1:3, z2=c(TRUE, TRUE, FALSE),
                    z3=c('tell', 'me', 'why'), z4=c(1, 2.4, 3.69) )
# plotting symbols circle, triangle, and "+"
qn1 <- with(tstDF, qqnorm2(y, z1))

# plotting symbols "x" and "o"
qn2 <- with(tstDF, qqnorm2(y, z2))

# plotting with "-" and "+"
qn. <- with(tstDF, qqnorm2(y, z2, pch=c('FALSE'='-', 'TRUE'='+')))

# plotting with "tell", "me", "why"
qn3 <- with(tstDF, qqnorm2(y, z3))

# plotting with the numeric values
qn4 <- with(tstDF, qqnorm2(y, z4))

##
## test plot, lines, points
##
plot(qn4, type='n') # establish the scales
lines(qn4)          # add a line
points(qn4)         # add points

##
## Check the objects created above
##
# check qn1
qn1. <- qqnorm(1:3, datax=TRUE, plot.it=FALSE)
qn1.$xlab <- 'y'
qn1.$ylab <- 'Normal scores'
qn1.$z <- tstDF$z1
qn1.$pch <- 1:3
names(qn1.$pch) <- 1:3
qn11 <- qn1.[c(3:4, 1:2, 5:6)]
class(qn11) <- 'qqnorm2'
stopifnot(
all.equal(qn1, qn11)
)

# check qn2
qn2. <- qqnorm(1:3, datax=TRUE, plot.it=FALSE)
qn2.$xlab <- 'y'
qn2.$ylab <- 'Normal scores'
qn2.$z <- tstDF$z2
qn2.$pch <- c('FALSE'=4, 'TRUE'=1)
qn22 <- qn2.[c(3:4, 1:2, 5:6)]
class(qn22) <- 'qqnorm2'
stopifnot(
all.equal(qn2, qn22)
)

# check qn.
qn.. <- qqnorm(1:3, datax=TRUE, plot.it=FALSE)
qn..$xlab <- 'y'
qn..$ylab <- 'Normal scores'
qn..$z <- tstDF$z2
qn..$pch <- c('FALSE'='-', 'TRUE'='+')
qn.2 <- qn..[c(3:4, 1:2, 5:6)]
class(qn.2) <- 'qqnorm2'
stopifnot(
all.equal(qn., qn.2)
)

# check qn3
qn3. <- qqnorm(1:3, datax=TRUE, plot.it=FALSE)
qn3.$xlab <- 'y'
qn3.$ylab <- 'Normal scores'
qn3.$z <- as.character(tstDF$z3)
qn3.$pch <- as.character(tstDF$z3)
names(qn3.$pch) <- qn3.$pch
qn33 <- qn3.[c(3:4, 1:2, 5:6)]
class(qn33) <- 'qqnorm2'
stopifnot(
all.equal(qn3, qn33)
)

# check qn4
qn4. <- qqnorm(1:3, datax=TRUE, plot.it=FALSE)
qn4.$xlab <- 'y'
qn4.$ylab <- 'Normal scores'
qn4.$z <- tstDF$z4
qn44 <- qn4.[c(3:4, 1:2, 5)]
qn44$pch <- NULL
class(qn44) <- 'qqnorm2'
stopifnot(
all.equal(qn4, qn44)
)

Run the code above in your browser using DataLab