Last data update: 2014.03.03

R: Normal Probability Plot with Multiple Symbols
qqnorm2R Documentation

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 plot function requires it.

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 qqnorm.)

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 FALSE and "o" for TRUE.

If z assumes integer values between 0 and 255, by default, the symbols are chosen as described with points.

Otherwise, by default, z is coerced to character, and the result is plotted.

If pch is provided, it must eitehr have names corresponding to levels of z, or z must be integers between 1 and length(pch).

...

Optional arguments.

For plot.qqnorm2, they are passed to plot.

For qqnorm2, they are passed to qqnorm and to plot.qqnorm2.

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], ...).

Value

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

Author(s)

Spencer Graves

See Also

qqnorm, qqnorm2s, plot points lines

Examples

##
## 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'

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'

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'

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'

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'

all.equal(qn4, qn44)


Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Ecfun)

Attaching package: 'Ecfun'

The following object is masked from 'package:base':

    sign

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Ecfun/qqnorm2.Rd_%03d_medium.png", width=480, height=480)
> ### Name: qqnorm2
> ### Title: Normal Probability Plot with Multiple Symbols
> ### Aliases: qqnorm2 plot.qqnorm2 lines.qqnorm2 points.qqnorm2
> ### Keywords: plot
> 
> ### ** Examples
> 
> ##
> ## 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'
> ## Don't show: 
> stopifnot(
+ ## End(Don't show)
+ all.equal(qn1, qn11)
+ ## Don't show: 
+ )
> ## End(Don't show)
> 
> # 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'
> ## Don't show: 
> stopifnot(
+ ## End(Don't show)
+ all.equal(qn2, qn22)
+ ## Don't show: 
+ )
> ## End(Don't show)
> 
> # 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'
> ## Don't show: 
> stopifnot(
+ ## End(Don't show)
+ all.equal(qn., qn.2)
+ ## Don't show: 
+ )
> ## End(Don't show)
> 
> # 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'
> ## Don't show: 
> stopifnot(
+ ## End(Don't show)
+ all.equal(qn3, qn33)
+ ## Don't show: 
+ )
> ## End(Don't show)
> 
> # 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'
> ## Don't show: 
> stopifnot(
+ ## End(Don't show)
+ all.equal(qn4, qn44)
+ ## Don't show: 
+ )
> ## End(Don't show)
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>