plotcorr: Plot correlation matrix ellipses

plotcorrR Documentation

Plot correlation matrix ellipses


This function plots a correlation matrix using ellipse-shaped glyphs for each entry. The ellipse represents a level curve of the density of a bivariate normal with the matching correlation.


plotcorr(corr, outline = TRUE, col = 'grey', numbers = FALSE, 
         type = c("full","lower","upper"),
	       diag = (type == "full"), bty = "n", axes = FALSE,
	       xlab = "", ylab = "", asp = 1,
	       cex.lab = par("cex.lab"), cex = 0.75*par("cex"),
	       mar = 0.1 + c(2,2,4,2), ...)



A matrix containing entries between -1 and 1 to be plotted as correlations.


Whether the ellipses should be outlined in the default colour.


Which colour(s) to use to fill the ellipses.


Whether to plot numerical correlations in place of ellipses. If numbers is TRUE, then the correlations will be rounded to a single decimal place and placed on the plot.


Character. Plot "full" matrix or just "upper" or "lower" triangular part of it.


Logical. Plot diagonal elements or not.

bty, axes, xlab, ylab, asp, mar, cex.lab, ...

Graphical parameters which will be passed to plot when plotting.


Graphical parameter which will be passed to text when plotting.


The ellipses being plotted will be tangent to a unit character square, with the shape chosen to match the required correlation. If numbers = FALSE, the col vector will be recycled to colour each of the ellipses; if TRUE, it will be ignored.


Duncan Murdoch; Gregor Gorjanc suggested the type and diag options.


Murdoch, D.J. and Chow, E.D. (1996). A graphical display of large correlation matrices. The American Statistician 50, 178-180. doi: 10.2307/2684435.

See Also



save.par <- par(ask = interactive())

# Plot the correlation matrix for the mtcars data full model fit 
fit <- lm(mpg ~ ., mtcars)
plotcorr(summary(fit, correlation = TRUE)$correlation)

# Plot a second figure with numbers in place of the
# ellipses
plotcorr(summary(fit, correlation = TRUE)$correlation, numbers = TRUE)

# Colour the ellipses to emphasize the differences.  The color range
# is based on RColorBrewer's Reds and Blues (suggested by Gregor Gorjanc)

corr.mtcars <- cor(mtcars)
ord <- order(corr.mtcars[1,])
xc <- corr.mtcars[ord, ord]
colors <- c("#A50F15","#DE2D26","#FB6A4A","#FCAE91","#FEE5D9","white",
plotcorr(xc, col=colors[5*xc + 6])

plotcorr(xc, col=colors[5*xc + 6], type = "upper")
plotcorr(xc, col=colors[5*xc + 6], type = "lower", diag = TRUE)

ellipse documentation built on June 1, 2022, 1:07 a.m.