DVC Day 20: Hotter Heat Map

(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:

Screen Shot 2015-05-03 at 8.27.09 AM

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()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s