R/format_corr.R

Defines functions format_corr

Documented in format_corr

#' Format correlation matrix for input into ggplot
#'
#' @param corr_matrix a correlation matrix derived from using stats::cor()
#'
#' @return convert matrix to tidy data with columns for `Var1` and `Var2` (the populations) and `value` (the correlation value)
#' @export
#'
#' @examples
#' corr <- calc_corr(sample_populations_all_groups)
#' format_corr(corr)
#'
#' @importFrom dplyr %>%
#' @importFrom rlang .data
#'
format_corr <- function(corr_matrix) {

  melted_corr <- reshape2::melt(corr_matrix) %>%
  dplyr::mutate(Var1 = as.factor(.data$Var1),
           Var2 = as.factor(.data$Var2))

  return(melted_corr)
}
aef1004/cytotypr documentation built on Dec. 25, 2021, 8:46 a.m.