Chapter 8 Adjacent plots

Adding adjacent plots to the heatmap is easy with superheat using the yt (‘y top’) and yr (‘y right’). yr and yt must have the same length as either:

  1. the number of rows/columns, or

  2. the number of row clusters/column clusters (for scatterplots, barplots, and boxplots only).

The plot types available for the adjacent plots are

The plot type can be specified using yt.plot.type = 'line', for example.

8.1 Scatterplots

The following example adds the miles per gallon (mpg) variable as a scatterplot next to the rows, and then orders the rows by the mpg variable. The yr argument takes a vector to plot next to the rows, while the yt argument takes a vector to plot next to the columns.

8.1.2 Color

Changing the color of the points in the scatterplot can be achieved using the yr.obs.col and yt.obs.col arguments, which are designed for specifying the color of individual data points.

For example, in the plot below, we are setting the fifth data point to be red, while the rest are grey. Note that the “fifth” data point corresponds to the fifth data point in the original matrix \(X\), rather than the re-ordered matrix (recall that the default order corresponds to a hierarchical clustering. To remove this ordering, specify pretty.order.rows = FALSE).

8.1.3 Clustering

If we cluster the cars into three groups based on the number of gears, then we can provide a yr whose length is either equal to nrow(X) or is equal to the number of clusters (length(membership.rows)), which in this case is equal to 3.

If yr has length equal to nrow(X) then we can specify the point colors using yr.obs.col as above.

Setting the color for each cluster can be achieved using the yr.cluster.col/yt.cluster.col arguments.

If yr has length equal to the number of clusters (which in this case would correspond to a vector of length three), then the three points are placed next to each cluster and yr.cluster.col/yt.cluster.col should be used to define the color for the points at the cluster-level.

8.2 Line plot

The line plot is a nice way of depicting a trend. Instead of plotting each data unit as a point connects the points via a continuous line. In the example below, we are plotting the miles per gallon as a line plot, and simultaneously ordering the rows by miles per gallon.

8.3 Smoothed line

The options for a smoothed line are much line those for the line plot above. Setting yt.plot.type/yr.plot.type to "smooth" will provide a loess smoothed line (default) or linear regression line based (set smoothing.method = "lm"). Color can be specified using yr.line.col/yt.line.col.

8.3.2 Linear regression line

A linear regression of miles per gallon versus number of cylinders (order.rows = order(mtcars$cyl)) is specified similarly with the additional argument smoothing.method = "lm".

Again, the standard error shading can be removed by specifying smooth.se = FALSE.

8.6 Barplot

Barplots are a particularly nice way of presenting and comparing values of a variable. Adding a barplot next to the columns and/or rows can be achieved by setting yr.plot.type = "bar" or yt.plot.type = "bar".

8.8 Axis options