CorrelationMatrix: Calculate and plot a pairwise correlations

Description Usage Arguments Details Value Author(s) Examples

Description

Takes a matrix or dataframe and calculates the pairwise correlations between all columns. Plots these as a ggplot tilemap. Optionally returns the pairwise correlations as a tidy tibble.

Usage

1
2
3
4
5
6
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

Optional label for x,y figure axes, Default: NULL

return.corr.tibble

Return the correlations?, Default: FALSE

plotit

Plot the correlations, Default: 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

Default: a ggplot2 object, optionally the correlations as a tibble.

Author(s)

Andrew Dolman

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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/ecustools documentation built on Jan. 15, 2022, 5:22 p.m.