CorrelationMatrix: Calculate and plot pairwise correlations

PlotPairwiseCorrelationsR Documentation

Calculate and plot pairwise correlations

Description

Takes a matrix or dataframe and calculates the pairwise correlations between all columns, and plots these as a ggplot tilemap. Optionally, the pairwise correlations can be returned as a tidy tibble.

Usage

PlotPairwiseCorrelations(
  M,
  axis.label = NULL,
  return.corr.tibble = FALSE,
  plotit = TRUE
)

Arguments

M

a matrix or dataframe for which the pairwise corrlelations between the columns are desired.

axis.label

charcter string with an optional label for the x and y figure axes; defaults to NULL (no label).

return.corr.tibble

logical; return the correlations as a tidy tibble? Defaults to FALSE.

plotit

logical; plot the correlations? Defaults to TRUE.

Details

Ideas for code taken from here: http://www.sthda.com/english/wiki/ggplot2-quick-correlation-matrix-heatmap-r-software-and-data-visualization

Value

Per default, a ggplot2 object; optionally, a list with two elements: the ggplot2 object and the correlations as a tibble.

Author(s)

Andrew Dolman

Examples

## Not run: 
if(interactive()) {

  M <- matrix(rnorm(12 * 100), ncol = 12)
  PlotPairwiseCorrelations(M, axis.label = "Month",
                           return.corr.tibble = TRUE)

  # Add names to columns
  colnames(M) <- letters[1:12]
  PlotPairwiseCorrelations(M, axis.label = "Cat",
                           return.corr.tibble = TRUE)

}

## End(Not run)

EarthSystemDiagnostics/grfxtools documentation built on Aug. 5, 2023, 1:43 p.m.