(This Post is part of my 30 day Data Visualization Challenge – you can follow along using the ‘challenge’ tag!)
After spending some more time thinking about heat maps, and reading the way that a few other R practitioners approach them (huge thanks to R-bloggers), I noodled around a bit with our earlier heat map to produce this, which I think is a bit more readable, and also provides more visually appetizing data bites:
Thoughts:
– Using only one triangle of the correlation matrix means we don’t repeat data, and it makes it a bit easier to pick out what you’re seeing.
– It’s interesting to see that depth and table have nearly no impact on price, and are in fact negatively correlated with one another – making negative correlations more visually apparent is a good move, I think, as it was tough to tell “uncorrelated” from “negatively correlated” in the last iteration of the heat map.
Code:
> library(ggplot2) > library(reshape2) > dnum <- diamonds[c(1,5:10)] > dnum <- sapply(dnum, as.numeric) > dcor <- round(cor(dnum), 2) > get_lower_tri <- function(cormat){ + cormat[lower.tri(cormat)] <- NA + return(cormat) + } > dcor <- get_upper_tri(dcor) > melted_dcor <- melt(dcor) > ggplot(data = melted_dcor, aes(Var2, Var1, fill=value)) + geom_tile(color="white") + scale_fill_gradient2(low="blue", high="orange", midpoint=0, limit=c(-1,1)) + theme_minimal()