liveBook · Manning

Melt()

As explained in Statistics Slam Dunk

The reshape2 melt() function reshapes tabular data into a long format by stacking combinations of variables and their values.

melt() reshapes a correlation matrix into a tabular structure by stacking every pair of variables into Var1 and Var2, with their coefficient in value. section 2.5.4

Use the result to prepare a correlation heat map:

  • Map Var1 and Var2 to heat-map axes and value to tile color with ggplot2. section 2.5.4

NBA draft correlations

For Age, games played (G), minutes played (MP), Win Shares (WS), and WS48, melt() produces 25 pairwise rows, including repeated matrix relationships and diagonal self-correlations.

How Statistics Slam Dunk covers it

How deep it goes
Converts a matrix into three columns, then stops before visualization and annotation.
Examples
Uses NBA draft correlations among Age, G, MP, WS, and WS48.
What it assumes
Assumes a correlation matrix created with cor() and teaches the required matrix-to-table transformation.
What you can do after
Apply it via reshape2 to turn a correlation matrix into plottable tabular data.
How it connects
Connects correlation matrices with ggplot2, geom_tile(), and heat maps.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.