Correlation matrix and plots


You want to calculate and visualize the correlation between continuous variables in a dataset.



Use functions within the corrplot package, as illustrated with the following example code.

#load required package
#read built-in example data
dat <- iris
#create pearson correlation matrix of continuous variables (1-4 for this example)
M<-cor(dat[,1:4], use="complete.obs", method="pearson")
#demo different options to plot/visualize the correlation matrix
corrplot(M, method="number")                      #display pearson correlation

corrplot(M, type="upper", method="number")        #only show upper half (removing redundant info)

corrplot(M, method="circle")                      #display graduated symbols

corrplot.mixed(M, lower="circle", upper="number") #hybrid of both


Anne-Marie Hodge and Jason Carlisle contributed to the development of this tool.