Learn R Programming

pedometrics (version 0.7.0)

plotCor: Correlation plot

Description

Plotting correlation matrices.

Usage

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

Arguments

r

Square matrix with correlation values.

r2

(optional) A second square matrix with correlation values.

col

(optional) Color table to use for image -- see image for details. The default is a colorblind-friendly palette ("RdBu") created using brewer.pal.

breaks

(optional) Break points in sorted order to indicate the intervals for assigning the colors. See 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.

Value

A correlation plot.

Details

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

plotCor also enables comparing correlations between the same variables at different points in time or space or for different observations. This can be 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.

Examples

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataLab