qrmtools (version 0.0-6)

plot_matrix: Graphical Tool for Visualizing Matrices

Description

Plot of a matrix.

Usage

plot_matrix(x, xlab = "Column", ylab = "Row",
            scales = list(alternating = c(1,1), tck = c(1,0), x = list(rot = 90)),
            at = NULL, colorkey = NULL, col = c("royalblue3", "white", "maroon3"),
            col.regions = NULL, ...)

Arguments

x

A matrix-like object.

xlab

The x-axis label.

ylab

The y-axis label.

scales

See levelplot(); if NULL, labels and ticks are omitted.

at

See levelplot(). If NULL, a useful default is computed based on the given values in x.

colorkey

See levelplot(). If NULL, a useful default is computed based on at.

col

A vector of length 3 providing the color key's default colors.

col.regions

See levelplot(). If NULL, a useful default is computed based on at.

Additional arguments passed to the underlying function levelplot().

Value

The plot, a Trellis object.

Details

Plot of a matrix.

Examples

Run this code
## Generate a random correlation matrix
d <- 50
L <- diag(1:d)
set.seed(271)
L[lower.tri(L)] <- runif(choose(d,2))
Sigma <- L <!-- %*% t(L) # ... real, symmetric, positive definite (covariance) matrix Sigma -->
P <- cor(Sigma)
## Default
plot_matrix(P)
## Default if nonnegative
plot_matrix(abs(P))
## Without diagonal
P. <- abs(P)
diag(P.) <- NA
plot_matrix(P.)
## Default if nonpositive
plot_matrix(-abs(P))
## Extending the color key to [-1,1] with darker color for |rho| >> 0
## Note: When specifying 'at', one most likely also wants to provide 'col.regions'
plot_matrix(P, at = seq(-1, 1, length.out = 200),
            col.regions = grey(c(seq(0, 1, length.out = 100), seq(1, 0, length.out = 100))))

Run the code above in your browser using DataCamp Workspace