plotcorr: Compact Visualization of a Correlation Matrix

Description Usage Arguments Details Author(s) References See Also Examples

Description

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.

This is a fork of the original plotcorr function from the ellipse package as at version 0.3-8. The arguments numbers, type, and diag have been replaced by lower.panel, upper.panel, and diag.panel similar to pairs. This enables displaying numbers in one triangle and ellipses in the other. However, there is no support for diag = FALSE in the original sense of the function.

Usage

1
2
3
4
5
plotcorr(corr, outline = TRUE, col = TRUE,
         lower.panel = "ellipse", upper.panel = "number", diag.panel = NULL,
         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), ...)

Arguments

corr

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

outline

Whether the ellipses should be outlined in the default colour.

col

Which colour(s) to use to fill the ellipses (recycled to length(corr)). The special setting col = TRUE will fill the ellipses according to the color range colorRampPalette(c("blue", "white", "red"))(11) mapped to the correlations as shown in the example below.

lower.panel, upper.panel, diag.panel

each panel can be either NULL, "ellipse", or "number". NULL disables the respective part, and "number" plots numerical correlations in place of ellipses. Correlations will be rounded to a single decimal place. The ellipse package is required for "ellipse" panels.

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

Graphical parameters which will be passed to plot when plotting.

cex

Graphical parameter which will be passed to text when plotting.

Details

The ellipses being plotted will be tangent to a unit character square, with the shape chosen to match the required correlation.

Author(s)

(of this fork) Sebastian Meyer, (of the original version) Duncan Murdoch

References

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

See Also

ellipse

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
if (requireNamespace("ellipse")) {
  ## Plot the correlation matrix for the mtcars data full model fit 
  data("mtcars")
  fit <- lm(mpg ~ ., mtcars)
  corr.fit <- summary(fit, correlation = TRUE)$correlation
  plotcorr(corr.fit, col = "gray")

  ## with default color coding
  plotcorr(corr.fit, col = TRUE)

  ## Colour the ellipses and order by correlations with miles/gallon
  corr.mtcars <- cor(mtcars)
  ord <- order(corr.mtcars[1,])
  xc <- corr.mtcars[ord, ord]
  colors <- colorRampPalette(c("blue", "white", "red"))(11)
  plotcorr(xc, col = colors[5*xc + 6])
}

biostatUZH documentation built on May 2, 2019, 6:06 p.m.