Created on 2 Aug 2013
Revised on Fri Aug 02 14:05:43 2013
original post is here
data(attitude)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.0.1
library(reshape2)
## Warning: package 'reshape2' was built under R version 3.0.1
qplot(x = Var1, y = Var2, data = melt(cor(attitude)), fill = value, geom = "tile")
cor makes a correlation matrix with all the pairwise correlations between variables (twice; plus a diagonal of ones).
melt takes the matrix and creates a data frame in long form, each row consisting of id variables Var1 and Var2 and a single value.
qplot plot with the tile geometry, mapping the indicator variables to rows and columns, and value (i.e. correlations) to the fill colour.