Learn R Programming

plotrix (version 2.3-1)

color2D.matplot: Display a numeric matrix as color matrix

Description

Display the values of a numeric 2D matrix or data frame as colored rectangles or hexagons.

Usage

color2D.matplot(x,redrange=c(0,1),greenrange=c(0,1),bluerange=c(0,1),
  extremes=NA,show.legend=FALSE,nslices=10,xlab="Column",ylab="Row",
  do.hex=FALSE,axes=TRUE,show.values=FALSE,vcol="white",vcex=1,...)

Arguments

x
data values
redrange, greenrange, bluerange
the ranges of red, green and blue that will be scaled to represent the range of numeric values
extremes
The colors for the extreme values of x. Takes precedence over the color ranges.
show.legend
whether to display a color legend with the extreme numeric values in the lower left corner of the plot. If the default is not suitable, call color.legend separately.
nslices
The number of color "slices" in the legend.
xlab,ylab
axis labels for the plot.
do.hex
plot packed hexagons instead of rectangles.
axes
Whether to suppress the default axis labelling.
show.values
Whether to display the numeric values of x.
vcol
The color for the value display.
vcex
The character expansion for the value display.
...
arguments passed to plot.

Value

  • nil

Details

Displays a plot with the same number of rectangular cells as there are numeric values in the matrix or data frame. Each rectangle is colored to represent its corresponding value. The rectangles are arranged in the conventional display of a 2D matrix with rows beginning at the top and columns at the left. The color scale defaults to black for the minimum value and white for the maximum. The user will have to adjust the plot device dimensions to get regular squares or hexagons, especially when the matrix is not square. As the margins are not equivalent for all display devices, this is currently a matter of trial and error.

See Also

color.scale, image

Examples

Run this code
x<-matrix(rnorm(1024)+sin(seq(0,2*pi,length=1024)),nrow=32)
 color2D.matplot(x,c(1,0),c(0,0),c(0,1),show.legend=TRUE,
  xlab="Columns",ylab="Rows",main="2D matrix plot")
 # now do hexagons
 color2D.matplot(x,c(1,0),c(0,0),c(0,1),show.legend=TRUE,
  xlab="Columns",ylab="Rows",do.hex=TRUE,main="2D matrix plot (hexagons)")
 # do a color only association plot
 xt<-table(sample(1:10,100,TRUE),sample(1:10,100,TRUE))
 observed<-xt[,rev(1:dim(xt)[2])]
 expected<-outer(rowSums(observed),colSums(observed),"*")/sum(xt)
 deviates<-(observed-expected)/sqrt(expected)
 color2D.matplot(x=round(deviates,2),redrange=c(1,0.5,0),
  greenrange=c(0,0.5,0),bluerange=c(0,1),
  show.values=TRUE,main="Association plot")

Run the code above in your browser using DataLab