08 March 2016

Interactive heatmap of correlation matrix

I saw this tweet yesterday afternoon.
Earlier that same morning I had been perusing a presentation that Karl Broman gave at JSM2015, Interactive graphics for high-dimensional genetic data. The talk included an interactive heatmap of a correlation matrix (slide 7) that seemed like it would be useful to many folks, not just those working with genetics data.

It was time to give it a try.

It couldn't have been much simpler. I had to install the R package qtlcharts, then use the function iplotCorr().
iplotCorr(mat=mtcars, group=mtcars$cyl, reorder=TRUE)

The first argument, mat=, is a data matrix where the rows represent observations and the columns represent variables. The second argument, group=, applies color coding to the scatterplot. The reorder= argument allows the variables to be arranged according to a built-in clustering algorithm. The output is an interactive heatmap of the correlation matrix. Hover over the heatmap to see the row, column, and cell values. Click on a cell to see a scatterplot with symbols colored by group.
I replied to the tweet with the full code.

One feature I would like to add to this graphic is a legend of some kind for the group colors in the scatterplot. Hovering over the points in the scatterplot gives the name of the row (the observation or individual), but it doesn't specifically decode the color (in my example, the number of cylinders, 4 is red, 6 is green, and 8 is blue).

No comments:

Post a Comment