corrplot {corrplot}R Documentation

A visualization of a correlation matrix.

Description

A graphical display of a correlation matrix, test for correlation, and other visualization methods about association and correlation. The details of graph are paid great attention to.

corrplot.circle, corrplot.square, corrplot.ellipse, corrplot.number, corrplot.pie, corrplot.shade, and corrplot.color are convenience wrappers of corrplot that take the same arguments as the corresponding option it replaces such as circle, ellipse etc. The corrplot function is more flexible than the wrappers.

corrplot.mtest function is also a wrapper of corrplot, however it can calculate correlation (input parameter corr), p-value (input parameter p.mat) and confidence interval (input parameter low.mat and upp.mat) from original data.frame or matrix (input parameter dat) automatically, while corrplot function need more input parameters because it does not support input parameter dat. Consequently, corrplot.mtest function is strongly recommended if you want to visualize the result of test for correlation.

Usage

corrplot(corr, method = c("circle", "square", "ellipse", "number", 
				"pie", "shade", "color"),
    type = c("full", "lower", "upper"), 
    order = c("original", "alphabet", "PCA", "hclust"),
    hclust.method = c("complete", "ward", "single", "average", 
    	               "mcquitty", "median", "centroid"),

    col = colorRampPalette(c("#67001F", "#B2182B", "#D6604D", "#F4A582", 
	    "#FDDBC7", "#F7F7F7", "#D1E5F0", "#92C5DE", 
	    "#4393C3", "#2166AC", "#053061"))(200),
             
    outline = FALSE, cex = 1, title = "", bg = "white",
    addcolorkey = TRUE, colorkey=c("-1to1","min2max"),
    cex.col.num = 0.8, mar = c(0,0,2,0),
    			
    addtextlabel = TRUE, pos.text = c("sides","diag"), col.text = "red",
    			
    shade.method = c("negtive", "positive", "all"),
    lwd.shade = 1, col.shade = "white", 
    			
    			
    addgrid = TRUE, col.grid = "gray", diag = TRUE,   
    addnum = FALSE,  col.num = NULL, 
    			
    corr.mtest = FALSE, p.mat = NULL, conf.level = 0.95,
    non_corr.method = c("pch","blank"),
    pch = 4, col.pch = "red",  cex.pch = 1,
    plotConf = FALSE, low.mat = NULL, upp.mat = NULL)
		
corrplot.circle(corr, ...)
corrplot.ellipse(corr,...)
corrplot.number(corr, ...)
corrplot.pie(corr, ...)
corrplot.shade(corr, ...)
corrplot.square(corr, ...)
corrplot.shade(corr, ...)
corrplot.mtest(dat = NULL, corr = NULL, p.mat = NULL, conf.level = 0.95,
	plotConf = FALSE, low.mat = NULL, upp.mat = NULL, 
    non_corr.method = c("pch","blank"), method = c("circle","square"),
    pch = 4, col.pch = "black",...)

Arguments

corr the correlation matrix, must be square if order is not "original" (default).
method the visualization method of correlation matrix to be used. Currently, it support seven methods, named "circle", "square", "ellipse", "number", "pie", "shade" and "color" for function corrplot, and "circle", "square" for function corrplot.mtest.
type plot "full" matrix or just "upper" or "lower" triangular part of it.
order the ordering method of the correlation matrix, need square matrix.
  • "original" for orginal order.
  • "alphabet" for alphabetical order.
  • "PCA" for principal component analysis.
  • "hclust" for hierarchical clustering.
hclust.method the agglomeration method to be used when order is hclust. This should be one of "ward", "single", "complete", "average", "mcquitty", "median" or "centroid".

col vector(any length), the color of glyphs.
outline logical, whether plot outline of circles, square and ellipse or not.
cex numeric, for the text label (variable names).
title title of the graph.
bg the background color.
addcolorkey whether add colorkey or not.
colorkey style of colorkey, must be "-1to1" or "min2max".
cex.col.num cex of the number in colorkey.
mar see par.
addtextlabel logical, whether add text label or not.
pos.text position of text labels, if "sides", all the text labels will be plot on sides; if "diag" (only valid when type is upper or lower), a set of text labels will be plot near the principal diagonal.
col.text the color of text label.
shade.method shade method, only valid when method is shade. If negative, then the negtive correlation will be shaded; if positive, then the positive correlation will be shaded; If all, then all correlation will be shaded. Note: the angle of shade line is different, 45 degrees for positive and 135 degrees for negtive.
lwd.shade the line width of shade.
col.shade the color of shade line.
addgrid logical, whether add grid or not.
col.grid the color of grid.
diag logical, whether display the correlation of the principal diagonal.
addnum logical, whether to plot numerical correlations on glyphs. Note: the figures are expressed in terms of a percentage for spacesaving.
col.num col of numerical correlations.
corr.mtest logical, whether to visualize the result of test for correlation. Note: need input parameters dat (only supported by function corrplot.mtest) or p.mat if TRUE.
p.mat matrix of p-value, function corrplot.mtest can also calculate it from input parameter dat.
conf.level confidence level for the returned confidence interval (valid in function corrplot.mtest()) and calculating the level of significance.
non_corr.method the method to deal with the correlation whose p-value is less than level of significance (1-conf.level), if "blank", wipe away the corresponding glyphs; if "pch", add character on the corresponding glyphs.
pch plotting character for the correlation whose p-value is less than level of significance (only valid when non_corr.method is pch).
col.pch the color of pch (only valid when non_corr.method is pch).
cex.pch the cex of pch (only valid when non_corr.method is pch).
plotConf logical, whether to plot confidence interval or not. Note: need input parameters dat (only supported by function corrplot.mtest) or low.mat and upp.mat if TRUE.
low.mat matrix of the lower bound of confidence interval, function corrplot.mtest can also calculate it from input parameter dat automatically.
upp.mat matrix of the upper bound of confidence interval, function corrplot.mtest can also calculate it from input parameter dat automatically.
dat original data.frame or matrix for function corrplot.mtest, corrplot.mtest can calculate correlation , p-value and confidence interval automatically from dat.
... extra parameters.

Details

method shoud be circle or square if draw confidence interval (plotConf = TRUE). Cairo package is strongly recommended to produce high-quality PNG, JPEG, TIFF bitmap files, especially for that method is circle, ellipse or pie.

Note

Using circles or squares with different areas and colors to display a correlation matrix, test for correlation's p-values and confidence intervals is Taiyun Wei's pioneering work.

Author(s)

Taiyun Wei

References

Michael Friendly (2002). Corrgrams: Exploratory displays for correlation matrices. The American Statistician, 56, 316–324.

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

See Also

The plotcorr function in the ellipse package and corrgram function in the corrgram package has some similarities.

Examples

## Not run: 

data(mtcars)
corr <- cor(mtcars)
par(ask = TRUE)

corrplot(corr, method="circle", order = "PCA")
##same as corrplot.circle(corr, order = "PCA")

corrplot(corr, method="square", order="hclust", type="upper", diag=FALSE, pos.text="diag")
##same as corrplot.square(corr, order="hclust", type="upper", diag=FALSE, pos.text="diag")

corrplot(corr, method="shade", order="PCA", shade.method = "negtive", col.grid="white")
##same as corrplot.shade(corr,order="PCA", shade.method = "negtive", col.grid="white")

corrplot(corr, method="ellipse", order="PCA", colorkey = "min2max", type="lower", pos.text="diag")
##same as corrplot.ellipse(corr, order="PCA", colorkey = "min2max", type="lower", pos.text="diag")

corrplot(corr, method="number", order="PCA")
##same as corrplot.number(corr, order="PCA")

corrplot(corr, method="color", order="alphabet", col.grid="white")
##same as corrplot.color(corr, order="alphabet", col.grid="white")

corrplot(corr, method="pie", order="hclust", hclust.method="median")
##same as corrplot.pie(corr, order="hclust", hclust.method="median")

## like Chinese wiqi
corrplot(corr, bg="gold2", col = c("white","black"), order="PCA", outline=TRUE, addcolorkey=FALSE)
## note the parameter outline
corrplot(corr, col = c("white","black"), order="PCA",  addcolorkey=FALSE, outline=TRUE)

## visualize the result of test for correlation
corrplot.mtest(dat=mtcars)
corrplot.mtest(dat=mtcars, plotC=TRUE)
corrplot.mtest(dat=mtcars, method="square", non_corr.method = "blank", addgrid=FALSE)
corrplot.mtest(dat=mtcars, plotC=TRUE, method="square", addgrid=FALSE)

##the input matrix is not square
corrplot(corr[1:8,], method="shade")
corrplot(corr[1:8,], method="number",  type="upper",diag=FALSE, addgrid=TRUE, pos.text="diag")
corrplot(corr[,1:8], method="number",  type="upper",diag=FALSE, addgrid=TRUE, pos.text="diag")

## End(Not run)

[Package corrplot version 0.1-0 Index]