plotCor {pedometrics}R Documentation

Correlation plot

Description

Plotting correlation matrices.

Usage

plotCor(r, r2, col, breaks, col.names, ...)

Arguments

r

A square matrix with correlation values.

r2

(optional) A second square matrix with correlation values.

col

(optional) Color table to use for image – see graphics::image() for details. The default is a colorblind-friendly palette created using the RColorBrewer palette "RdBu".

breaks

(optional) Break points in sorted order to indicate the intervals for assigning the colors. See fields::image.plot() for more details.

col.names

(optional) Character vector with short (up to 5 characters) column names.

...

(optional) Additional parameters passed to plotting functions.

Details

A correlation plot in an alternative way of showing the strength of the empirical correlations between variables. This is done by using a diverging color palette, where the darker the color, the stronger the absolute correlation value.

plotCor() can also be used to compare correlations between the same variables at different points in time or space or for different observations. This is done by passing two square correlation matrices using arguments r and r2. The lower triangle of the resulting correlation plot will contain correlations from r, correlations from r2 will be in the upper triangle, and the diagonal will be empty.

Value

A correlation plot.

Dependencies

The fields package, provider of tools for spatial data in R, is required for plotCor() to work. The development version of the fields package is available on https://github.com/dnychka/fieldsRPackage while its old versions are available on the CRAN archive at https://cran.r-project.org/src/contrib/Archive/fields/.

Author(s)

Alessandro Samuel-Rosa alessandrosamuelrosa@gmail.com

References

Neuwirth E (2022). RColorBrewer: ColorBrewer Palettes. R package version 1.1-3, https://CRAN.R-project.org/package=RColorBrewer.

Examples

if (all(c(require(sp), require(fields)))) {
  data(meuse, package = "sp")
  cols <- c("cadmium", "copper", "lead", "zinc", "elev", "dist", "om")

  # A single correlation matrix
  r <- cor(meuse[1:20, cols], use = "complete")
  r <- round(r, 2)
  plotCor(r)

  # Two correlation matrices: r2 goes in the upper triangle
  r2 <- cor(meuse[21:40, cols], use = "complete")
  r2 <- round(r2, 2)
  plotCor(r, r2)
}

[Package pedometrics version 0.12.1 Index]