Learn R Programming

plotrix (version 3.7)

multivari: Function to draw a multivari chart

Description

A multivari chart of one quantitative response variable depending on two to four categorical variables can be drawn.

Usage

multivari(var, fac1, fac2, fac3 = NULL, fac4 = NULL, data, sort = FALSE,
 fun = mean, pch = list(15, 16, 17), col = list("black", "blue", "red"),
 col0 = "black", cex = 1, fac.cex = 2, xlab.depth = 3, legend = FALSE,
 main = paste("multivari chart of", var), ...)

Arguments

var

variable name (character string) or column index of response variable, required

fac1

variable name (character string) or column index of first level factor, required

fac2

variable name (character string) or column index of second level factor, required

fac3

variable name (character string) or column index of third level factor, optional

fac4

variable name (character string) or column index of fourth level factor, optional; can only be specified if there is also a third level factor; separate multivari charts for the first three factors are drawn for each level of this factor

data

a data frame, required

sort

logical, specifying whether or not levels are sorted, when converting character vectors to factors (a single choice for all factors is needed); default: FALSE

fun

a function to be used in aggregation; default: mean

pch

a list of length 2 or 3, depending on whether or not fac3 is specified; the ith list element can be an individual plotting symbol (like the usual pch entry) or a vector of plot symbols for each level of fac_i

col

a list of length 2 or 3, depending on whether or not fac3 is specified; the ith list element can be an individual color or a vector of colors for each level of fac_i; this color specification is used for the plot symbols of fac_i levels and for the lines connecting the symbols for the next level in the hierarchy

col0

the color for the first line to be drawn

cex

the size of the annotation text below the horizontal axis (annotation of the fourth level header is 1.5 times this size)

fac.cex

a multiplier for cex; plot symbol sizes are fac.cex*cex; default: 2

xlab.depth

labels for the horizontal axis are printed down to this level of the hierarchy (default: 3); if the depth is reduced, different plot symbols should be used, and a legend should be drawn

legend

logical determining whether or not a legend should be drawn (default: FALSE); the function determines wether top right or bottom right yields a better position (it is not guaranteed that there is no overlab); if this does not work well, one can manually draw a legend in the outer margin

main

title, as usual; a default is provided

further arguments to functions plot, lines, points, mtext

Value

a list of (lists of) data frames with summary statistics to be plotted

Details

A multivari chart as implemented here mainly serves exploratory purposes. It works particularly well with balanced data, and it serves the purpose to visualize an interaction of degree up to four. The order of the factors can make a big difference in the display. If there is no natural order, it may be worthwhile inspect several orders.

The function is inspired by Minitabs behavior for multivari charts. It does not attempt to visualize individual observations.

For interactions with two factors only, it is often preferrable to use function interaction.plot.

See Also

See also interaction.plot

Examples

Run this code
# NOT RUN {
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.
# }
# NOT RUN {
require(car)
multivari("cycles", "len", "load", "amp", data=Wool, 
    col=list("black","red",c("grey70","grey45","grey20")),
    pch=list(15,17,8), legend=TRUE, xlab.depth = 2, lwd=2)
multivari("cycles", "load", "len", "amp", data=Wool, 
    col=list("black",c("red","blue","darkgreen"),
    c("grey70","grey45","grey20")),
    pch=list(15,17,8), legend=TRUE, xlab.depth = 2, lwd=2)
    
## create a fake fourth factor
fakedat <- rbind(cbind(newfac="blabla",Wool),cbind(newfac="albalb",Wool))
## make it character for demonstrating the effect of sort option
fakedat$newfac <- as.character(fakedat$newfac)

## default: sort order in the data is respected (order of unique is used)
multivari("cycles", "load", "len", "amp", "newfac", data=fakedat, 
    col=list("black",c("red","blue","darkgreen"),
    c("grey70","grey45","grey20")),
    pch=list(15,17,8), legend=TRUE, xlab.depth = 2, lwd=2, cex=0.8)
    
## sort=TRUE: levels are sorted (order of sort(unique))
multivari("cycles", "load", "len", "amp", "newfac", data=fakedat, 
    col=list("black",c("red","blue","darkgreen"),
    c("grey70","grey45","grey20")),
    pch=list(15,17,8), legend=TRUE, xlab.depth = 2, lwd=2, cex=0.8,
    sort=TRUE)
# }

Run the code above in your browser using DataLab