quadPlot: Creates a "four-color" plot for interpreting data with...

View source: R/quadPlot.r

quadPlotR Documentation

Creates a "four-color" plot for interpreting data with mixtures of four aspects.

Description

This function creates a "quad-plot" used for interpreting data that represents four aspects of each subject (e.g., the probability that an individual belongs to one of four populations). The plot is typically a square with each corner assigned a different color. The closer an object in the main plot is to one of four "assignments" (e.g., populations), the more the corresponding color is shown, with assignments of intermediate value displaying as a mixture of colors. Labels for the four corners can be added.

Usage

quadPlot(
  x,
  cols = c("white", "cyan", "black", "red"),
  main = "",
  labels = colnames(x),
  labelCex = 0.6,
  labelAdj = 1,
  background = TRUE,
  n = 25,
  style = "pies",
  pch = 21,
  radius = 0.01,
  border = "black",
  na.rm = FALSE,
  ...
)

Arguments

x

Data frame or matrix with 4 columns, each representing the relative probabilities of belonging to one of 4 aspects. Each row will be represented by a point on the plot.

cols

Character list. Names of four colors to be used to create a gradient to fill the color swatch. The first color will be assigned to the lower left corner, the second to the upper left, third to upper right, and fourth to lower right. Note that not every color combination produces a map with a unique color at each coordinate of the color swatch.

labels

Character vector used to name the four corners of the color swatch in this order: bottom left, top left, top right, bottom right. Leave as NULL to skip displaying labels. The default is to use the names of the four columns of x.

labelCex

Numeric, size of label text.

labelAdj

Numeric, usually between 0 and 1. Position of corner labels relative to the corners of the swatch.

background

Logical, if TRUE then color the background of the plot using the color-coding scheme.

n

Positive integer, number of squares used to approximate a smooth color map for the background. This is the number of cells along each side of the swatch. Higher values create less "blocky" plots but increase drawing time.

style

Character, either 'pies' in which case each point is represented by a link[omnibusPlots]{pies} plot or 'points' in which case each point is represented by a point with its color a product of its four aspects.

pch

Used when style is 'points'. Either a number or . indicating the type of symbol to draw (see link[graphics]{points}).

na.rm

Logical, if TRUE then remove lines in x that have at least one NA.

...

Arguments to pass to points, plot, polygon, or text.

Details

Note that there is not a unique (1-to-1) mapping of the 4 values to position on the plot. For example, if belonging solely to population A is represented by placing a point in the lower left corner, population B in the upper left, C the upper right, and D the lower right, then belonging strongly to population A and weakly to C will place a point near the location close to the location where a point belonging strongly to A and weakly to B and D will also lie.

Value

Nothing (side effect is to create a plot).

See Also

colorFrom4Vector, legendQuad

Examples

data(religion)
head(religion)
religion$others <- rowSums(religion[ , c('unaffiliated', 'hindu', 'folk', 'other', 'jewish')])
religs <- c('christian', 'muslim', 'buddhist', 'others')
par(mfrow=c(1, 2))
quadPlot(religion[ , religs], main='Religion by Country', radius=0.04)
quadPlot(religion[ , religs], 'points', background=FALSE, main='Religion by Country', cex=2)

adamlilith/legendary documentation built on July 28, 2023, 8:13 p.m.