R: Colors a symmetric matrix

dmat.color {gclus} | R Documentation

## Colors a symmetric matrix

### Description

Accepts a dissimilarity matrix or `dist` `m`, and returns a matrix of colors. Values in `m` are `cut` into categories using `breaks` (ranked distances if `byrank` is `TRUE`) and categories are assigned the values in `colors`.

### Usage

    dmat.color(m, colors = default.dmat.color, byrank = NULL, breaks = length(colors))

### Arguments

`m` | a dissimilarity matrix or the result of `dist`
`colors` | a vector of colors. The default is `default.dmat.color`.
`byrank` | boolean, default `TRUE` is unless `breaks` has length > 1.
`breaks` | the number of break points.

### Details

`breaks` are passed to the function`cut`. If `byrank` is `TRUE`, values in `m` are ranked before they are categorized. If `byrank` is `TRUE` and `breaks` is an integer, then there are `breaks` equal-sized categories.

### Value

Returns a matrix of colors. The matrix is symmetric, with NAs on the diagonal.

### Author(s)

Catherine B. Hurley

### See Also

`cut`, `cpairs`, `cparcoord`

### Examples

    data(longley)
    longley.cor <- cor(longley)
    # A matrix with equal (or nearly equal) number of entries of each color.
    longley.color <- dmat.color(longley.cor)

    # Plot the colors
    plotcolors(longley.color,dlabels=rownames(longley.color))

    # Try different color schemes

    # A matrix where each color represents an equal-length interval.
    longley.color <- dmat.color(longley.cor, byrank=FALSE)
    # Specify colors and breaks

    longley.color <- dmat.color(longley.cor, breaks=c(-1,0,.5,.8,1),
    cm.colors(4))

    # Could also reorder variables prior to plotting:

    longley.o <- order.single(longley.cor)
    longley.color <- longley.color[longley.o,longley.o]

    # The colors can be used in a scatterplot matrix or parallel
    # coordinate display:

    cpairs(longley, panel.color= longley.color)
    cparcoord(longley, panel.color= longley.color)

[Package gclus version 1.3.1 Index]