Skip to contents

Easily output a correlation matrix and export it to Microsoft Excel, with the first row and column frozen, and correlation coefficients colour-coded based on effect size (0.0-0.2: small (no colour); 0.2-0.4: medium (pink/light blue); 0.4-1.0: large (red/dark blue)), following Cohen's suggestions for small (.10), medium (.30), and large (.50) correlation sizes.

Based on the correlation and openxlsx2 packages.

WARNING: This function will replace cormatrix_excel (the original one) as soon as openxlsx2 is available from CRAN. In the meanwhile, it is experimental and subject to change. Use with care.

Usage

cormatrix_excel2(
  data,
  filename = "cormatrix",
  overwrite = TRUE,
  p_adjust = "none",
  print.mat = TRUE,
  ...
)

Arguments

data

The data frame

filename

Desired filename (path can be added before hand but no need to specify extension).

overwrite

Whether to allow overwriting previous file.

p_adjust

Default p-value adjustment method (default is "none", although correlation::correlation's default is "holm")

print.mat

Logical, whether to also print the correlation matrix to console.

...

Parameters to be passed to the correlation package (see ?correlation::correlation)

Author

Adapted from @JanMarvin (JanMarvin/openxlsx2#286) and the original rempsyc::cormatrix_excel

Examples

if (FALSE) {
# Basic example
cormatrix_excel2(mtcars)
cormatrix_excel2(iris, p_adjust = "none")
cormatrix_excel2(airquality, method = "spearman")
}