matrix_plot function

Graphical Tool for Visualizing Matrices

Graphical Tool for Visualizing Matrices

Plot of a matrix.

matrix_plot(x, ran = range(x, na.rm = TRUE), ylim = rev(c(0.5, nrow(x) + 0.5)), xlab = "Column", ylab = "Row", scales = list(alternating = c(1,1), tck = c(1,0), x = list(at = pretty(1:ncol(x)), rot = 90), y = list(at = pretty(1:nrow(x)))), at = NULL, colorkey = NULL, col = c("royalblue3", "white", "maroon3"), col.regions = NULL, ...)

Arguments

  • x: matrix-like object.
  • ran: range (can be used to enforce (-1,1), for example).
  • ylim: y-axis limits in reverse order (for the rows to appear 'top down').
  • xlab: x-axis label.
  • ylab: 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: vector of length two (if all values of x are non-positive or all are non-negative; note that also a vector of length three is allowed in this case) or three (if x contains negative and positive values) 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 levelplot().

Returns

The plot, a Trellis object.

Details

Plot of a matrix.

Author(s)

Marius Hofert

Examples

## Generate a random correlation matrix d <- 50 L <- diag(1:d) set.seed(271) L[lower.tri(L)] <- runif(choose(d,2)) # random Cholesky factor Sigma <- L P <- cor(Sigma) ## Default matrix_plot(P) matrix_plot(P, ran = c(-1, 1)) # within (-1, 1) matrix_plot(abs(P)) # if nonnegative L. <- L diag(L.) <- NA matrix_plot(L.) # Cholesky factor without diagonal ## Default if nonpositive matrix_plot(-abs(P)) ## Changing colors matrix_plot(P, ran = c(-1, 1), col.regions = grey(c(seq(0, 1, length.out = 100), seq(1, 0, length.out = 100)))) ## An example with overlaid lines library(lattice) my_panel <- function(...) { panel.levelplot(...) panel.abline(h = c(10, 20), v = c(10, 20), lty = 2) } matrix_plot(P, panel = my_panel)
  • Maintainer: Marius Hofert
  • License: GPL (>= 3) | file LICENCE
  • Last published: 2024-03-04

Useful links