plot.sociomatrix: Plot Matrices Using a Color/Intensity Grid

View source: R/visualization.R

plot.sociomatrixR Documentation

Plot Matrices Using a Color/Intensity Grid

Description

Plots a matrix, m, associating the magnitude of the i,jth cell of m with the color of the i,jth cell of an nrow(m) by ncol(m) grid.

Usage

## S3 method for class 'sociomatrix'
plot(x, labels=NULL, drawlab=TRUE, diaglab=TRUE, 
    drawlines=TRUE, xlab=NULL, ylab=NULL, cex.lab=1, font.lab=1, col.lab=1,
    scale.values=TRUE, cell.col=gray, ...)

sociomatrixplot(x, labels=NULL, drawlab=TRUE, diaglab=TRUE, 
    drawlines=TRUE, xlab=NULL, ylab=NULL, cex.lab=1, font.lab=1, col.lab=1,
    scale.values=TRUE, cell.col=gray, ...)

Arguments

x

an input graph.

labels

a list containing the vectors of row and column labels (respectively); defaults to the row/column labels of x (if specified), or otherwise sequential numerical labels.

drawlab

logical; add row/column labels to the plot?

diaglab

logical; label the diagonal?

drawlines

logical; draw lines to mark cell boundaries?

xlab

x axis label.

ylab

y axis label.

cex.lab

optional expansion factor for labels.

font.lab

optional font specification for labels.

col.lab

optional color specification for labels.

scale.values

logical; should cell values be affinely scaled to the [0,1] interval? (Defaults to TRUE.)

cell.col

function taking a vector of cell values as an argument and returning a corresponding vector of colors; defaults to gray.

...

additional arguments to plot.

Details

plot.sociomatrix is particularly valuable for examining large adjacency matrices, whose structure can be non-obvious otherwise. sociomatrixplot is an alias to plot.sociomatrix, and may eventually supersede it.

The cell.col argument can be any function that takes input cell values and returns legal colors; while gray will produce an error for cell values outside the [0,1] interval, user-specified functions can be employed to get other effects (see examples below). Note that, by default, all input cell values are affinely scaled to the [0,1] interval before colors are computed, so scale.values must be set to FALSE to allow access to the raw inputs.

Value

None

Author(s)

Carter T. Butts buttsc@uci.edu

See Also

plot.blockmodel

Examples

#Plot a small adjacency matrix
plot.sociomatrix(rgraph(5))

#Plot a much larger one
plot.sociomatrix(rgraph(100), drawlab=FALSE, diaglab=FALSE)

#Example involving a signed, valued graph and custom colors
mycolfun <- function(z){   #Custom color function
    ifelse(z<0, rgb(1,0,0,alpha=1-1/(1-z)), ifelse(z>0, 
        rgb(0,0,1,alpha=1-1/(1+z)), rgb(0,0,0,alpha=0)))
}
sg <- rgraph(25) * matrix(rnorm(25^2),25,25)
plot.sociomatrix(sg, scale.values=FALSE, cell.col=mycolfun)  #Blue pos/red neg

sna documentation built on June 1, 2022, 9:06 a.m.

Related to plot.sociomatrix in sna...