Chapter 12 Legend

12.1 Removing the legend

Removing the legend entirely can be achieved by setting legend = FALSE.

superheat(mtcars,
# scale the matrix columns
scale = TRUE,

# remove the legend
legend = FALSE)

12.2 Size

Changing the size of the legend can be achieved by setting legend.height and legend.width. The size of the text can be set using legend.text.size.

superheat(mtcars,
# scale the matrix columns
scale = TRUE,

# make the legend bigger
legend.height = 0.5,
legend.width = 2,
legend.text.size = 20)

12.3 Vertical spacing

You can increase or decrease the vertical space between the heatmap and the legend using the legeng.vspace argument. The default is set to 0.1.

superheat(mtcars,
# scale the matrix columns
scale = TRUE,

# increase the space between the heatmap and legend
legend.vspace = 0.4)

12.4 Legend breaks

Sometimes it is nice to customize the legend even further. Superheat tries to provide pretty legend breaks, but sometimes fails to do so. You can specify the desired number of breaks presented in the legend using the legend.num.ticks argument. Unfortunately, if the underlying pretty() function that decides the legend breaks does not think your number is a good choice, it will veto your suggestion and do whatever it wants instead.

superheat(mtcars,
# scale the matrix columns
scale = TRUE,

# specify the number of legend breaks
legend.num.ticks = 10)

Alternatively, the legend.breaks argument can be used to manually specify the legend break values (i.e. where the numbers and ticks appear). This argument does not mess with the actual color range or presentation.

superheat(mtcars,
# scale the matrix columns
scale = TRUE,

# manually specify the legend breaks
legend.breaks = c(-0.5, 0.5, 1.5))