16 Chart: Heatmap

16.1 Overview

This section covers how to make heatmaps.

16.2 tl;dr

Enough with these simple examples! I want a complicated one!

Here’s a heatmap of occupational categories of sons and fathers in the US, UK, and Japan:

And here’s the code:

For more info on this dataset, type ?vcdExtra::Yamaguchi87 into the console.

16.3 Simple examples

Too complicated! Simplify, man!

16.3.1 Heatmap of two-dimensional bin counts

For this heatmap, we will use the SpeedSki dataset.

Only two variables, x and y are needed for two-dimensional bin count heatmaps. The third variable–i.e., the color–represents the bin count of points in the region it covers. Think of it as a two-dimensional histogram.

To create a heatmap, simply substitute geom_point() with geom_bin2d():

16.4 Theory

Heat maps are like a combination of scatterplots and histograms: they allow you to compare different parameters while also seeing their relative distributions.

16.5 External resources