heat_map: No-frills heatmap

View source: R/heat_map.R

heat_mapR Documentation

No-frills heatmap

Description

Makes a heatmap with optional row/column ordering and aligned dendrograms.

Usage

heat_map(
  mat,
  ord = NULL,
  ord_x = NULL,
  ord_y = NULL,
  draw_dendro = FALSE,
  return_data = FALSE,
  show_legend = TRUE,
  plot_title = NULL,
  axis_text_x = colnames(mat),
  axis_text_y = rownames(mat),
  axis_title_x = waiver(),
  axis_title_y = waiver(),
  colours = c("red", "yellow"),
  limits = NULL,
  oob = scales::squish,
  legend_breaks = waiver(),
  legend_labels = waiver(),
  legend_title = waiver(),
  axis_ticks = element_blank(),
  axis_ticks_length = 0,
  axis_text_size = 7,
  plot_margin = c(5.5, 5.5, 5.5, 5.5),
  rel_widths = c(heatmap = 1, dend = 0.2, legend = 0.2),
  rel_heights = c(heatmap = 1, dend = 0.2),
  ...
)

Arguments

mat

A numeric matrix.

ord

An optional ordering object with which to reorder both the rows and the columns of mat. Can be an hclust object or an integer permutation vector.

ord_x

An optional ordering object with which to reorder the columns of mat. Can be an hclust object or an integer permutation vector. Ignored if ord is supplied.

ord_y

An optional ordering object with which to reorder the rows of mat. Can be an hclust object or an integer permutation vector. Ignored if ord is supplied.

draw_dendro

Logical or character indicating whether to draw dendrograms or which dendrograms to draw. Possible values are TRUE, FALSE, 'x', 'y', 'xy'. If TRUE or 'xy', all possible dendrograms will be drawn. Default: FALSE.

return_data

Logical indicating whether to return a data frame (in long format) containing the data used to construct the heatmap.

show_legend

Logical indicating whether to show the heatmap legend.

plot_title

The title of the plot. Set to NULL if you don't want a title. Default: NULL.

axis_text_x

Character vector of x axis labels. These will be re-ordered if ord or ord_x are supplied. Set to NULL if you want no x axis labels. Default: colnames(mat).

axis_text_y

Character vector of y axis labels. These will be re-ordered if ord or ord_y are supplied. Set to NULL if you want no y axis labels. Default: rownames(mat).

axis_title_x

The x axis title. Set to NULL if you want no x axis title.

axis_title_y

The y axis title. Set to NULL if you want no y axis title.

colours

The colours to be used in the heatmap. These will be converted to a colour scale by ggplot2's scale_fill_gradientn. Default: c('red', 'yellow').

limits

Two-element numeric vector specifying the limits to use for the colour scale.

oob

A function to handle values lying outside the range specified by limits. Default: scales::squish.

legend_breaks

A numeric vector of legend breaks.

legend_labels

A vector of legend labels.

legend_title

The legend title. Set to NULL if you want no legend title.

axis_ticks

As axis.ticks in theme.

axis_ticks_length

As axis.ticks.length in theme.

axis_text_size

The size of the axis text. Default: 7.

plot_margin

Numeric vector of plot margins in pts, in the order top, right, bottom, left. Default: c(5.5, 5.5, 5.5, 5.5).

rel_widths

Named vector of relative widths to be passed to cowplot's plot_grid. Names should include 'heatmap' and, if applicable, 'dend' and 'legend'.

rel_heights

Named vector of relative heights to be passed to cowplot's plot_grid. Names should include 'heatmap' and, if applicable, 'dend'.

...

Additional arguments to be passed to ggplot2's theme function in the construction of the heatmap.

Value

If return_data is FALSE, a ggplot object. If return_data is TRUE, a list with two elements: plot, a ggplot object; and data, a data frame.


m20ty/matkot documentation built on July 1, 2023, 8:11 p.m.