Learn R Programming

gghinton (version 0.1.0)

matrix_to_hinton: Convert a matrix to a tidy data frame for use with geom_hinton()

Description

Reshapes a numeric matrix into a long-form data frame with one row per matrix entry. Row 1 of the matrix is placed at the top of the resulting plot (highest y value), matching the visual convention of matrix notation.

Usage

matrix_to_hinton(
  x,
  rowname_col = "row",
  colname_col = "col",
  value_col = "weight"
)

Value

A data frame with columns named by rowname_col, colname_col, and value_col. If x has row or column names, additional columns row_label and col_label are included.

Arguments

x

A numeric matrix.

rowname_col

Name of the column that will hold the row index. Default "row".

colname_col

Name of the column that will hold the column index. Default "col".

value_col

Name of the column that will hold the matrix values. Default "weight".

Examples

Run this code
m <- matrix(c(0.8, -0.3, 0.5, -0.9, 0.1, 0.6), nrow = 2)
matrix_to_hinton(m)

# Named matrix
rownames(m) <- c("a", "b")
colnames(m) <- c("x", "y", "z")
matrix_to_hinton(m)

Run the code above in your browser using DataLab