R/reshape.R

Defines functions matrix_to_df

Documented in matrix_to_df

#' Reshape a correlation matrix into a data.frame
#'
#' This function takes a square matrix, like a correlation matrix derived from a
#' mean covariance matrix, and reshapes it into a data.frame for plotting.
#'
#' @param x A matrix with named x and y dimensions.
#'
#' @return A df with X, Y and value columns
#'
#' @importFrom tidyr pivot_longer
#' @export
matrix_to_df <- function(x) {
  data.frame(x) %>%
    mutate(X = names(.)) %>%
    pivot_longer(-X, names_to = "Y", values_to = "value")
}
gjcooper/gcphd-model_of_dce documentation built on March 25, 2024, 8:57 a.m.