gl.plot.heatmap: Represents a distance matrix as a heatmap

View source: R/gl.plot.heatmap.r

gl.plot.heatmapR Documentation

Represents a distance matrix as a heatmap

Description

Plots a heat map of the values in a distance or dissimilarity matrix, with optional row and column dendrograms. When a genlight object is supplied, individuals are coloured by population in side bars and a legend. The heat map is drawn by utils.heatmap, a modified copy of gplots::heatmap.2.

Usage

gl.plot.heatmap(
  D,
  x = NULL,
  palette.divergent = gl.colors("div", verbose = 0),
  palette_discrete = NULL,
  dendrogram = "column",
  plot.out = TRUE,
  legend.print = TRUE,
  legendx = 0,
  legendy = 0.5,
  label.size = 0.75,
  legend.title = "Populations",
  diag.na = FALSE,
  margins = c(10, 10),
  na.color = "grey",
  revC = FALSE,
  symbreaks = FALSE,
  trace = "none",
  tracecol = "cyan",
  cexRow = NULL,
  cexCol = NULL,
  srtRow = NULL,
  srtCol = 90,
  offsetRow = 0.5,
  offsetCol = 0.5,
  key = TRUE,
  keysize = 1.5,
  density.info = "none",
  denscol = "cyan",
  symkey = FALSE,
  densadj = 0.25,
  key.title = NULL,
  key.xlab = NULL,
  key.ylab = NULL,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  verbose = NULL,
  ...
)

Arguments

D

Distance matrix (class dist), square numeric matrix, or object of class fd [required].

x

Genlight object used to colour individuals by population [default NULL].

palette.divergent

A divergent palette function for the values [default gl.colors("div")].

palette_discrete

Colours for the populations of x: a palette function, or a vector with one colour per population [default NULL, in which case colours are chosen by gl.select.colors].

dendrogram

Which dendrograms to draw: 'none', 'row', 'column' or 'both' [default "column"].

plot.out

Whether to draw the heat map [default TRUE].

legend.print

Whether to draw the population legend (only when x is supplied and matches D) [default TRUE].

legendx

x position of the legend, 0-1, or a legend keyword [default 0].

legendy

y position of the legend, 0-1 [default 0.5].

label.size

Size of the population labels in the legend [default 0.75].

legend.title

Legend title [default "Populations"].

diag.na

If TRUE, the diagonal of the matrix is set to NA and drawn in na.color [default FALSE].

margins

Numeric vector of length 2: margins for column and row names, respectively [default c(10, 10)].

na.color

Colour for missing values (NA) [default "grey"].

revC

Reverse column order [default FALSE].

symbreaks

Symmetric colour breaks around zero [default FALSE].

trace

Trace lines: "column", "row", "both" or "none" [default "none"].

tracecol

Trace line colour [default "cyan"].

cexRow

Row label scale [default NULL, chosen from the number of rows].

cexCol

Column label scale [default NULL, chosen from the number of columns].

srtRow

Row label rotation angle [default NULL].

srtCol

Column label rotation angle [default 90].

offsetRow

Row label offset [default 0.5].

offsetCol

Column label offset [default 0.5].

key

Draw the colour key [default TRUE].

keysize

Size of the colour key [default 1.5].

density.info

Density plot on the colour key: "histogram", "density" or "none" [default "none"].

denscol

Density plot colour [default "cyan"].

symkey

Symmetric colour key around zero [default FALSE].

densadj

Density plot bandwidth adjustment [default 0.25].

key.title

Title of the colour key [default NULL].

key.xlab

X label of the colour key [default NULL].

key.ylab

Y label of the colour key [default NULL].

main

Main plot title [default NULL].

xlab

X-axis label [default NULL].

ylab

Y-axis label [default NULL].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, brief progress messages; 3, progress and results summary; 5, full report [default 2, unless specified using gl.set.verbosity].

...

Further arguments passed to utils.heatmap.

Details

D can be a dist object (for example from gl.dist.ind or gl.dist.pop), a square numeric matrix with matching row and column names, or an object of class fd from gl.fixed.diff, in which case the raw fixed difference matrix ($fd) is plotted. A matrix is plotted as supplied: its diagonal and both triangles are drawn, so a relatedness matrix keeps its self-relatedness values and an asymmetric matrix keeps both directions. If one triangle is entirely NA, it is filled from the other. Set diag.na = TRUE to leave the diagonal blank.

Population colours are drawn when every column of D names an individual of x. When D is at the population level (gl.dist.pop, fd), x is ignored. When some columns of D are not individuals of x, no colours are drawn and a warning is printed at verbose >= 1.

legendx and legendy position the legend in the 0-1 coordinates of the plotting region; legendx also accepts a keyword such as "topleft" (see legend).

Value

Invisibly, the list returned by utils.heatmap (row and column orders, the plotted matrix, dendrograms, breaks and colours), or NULL when plot.out = FALSE.

Author(s)

Author(s): Luis Mijangos. Custodian: Luis Mijangos – Post to https://groups.google.com/d/forum/dartr

See Also

Other graphics: gl.colors(), gl.map.interactive(), gl.plot.snp.density(), gl.select.colors(), gl.select.shapes(), gl.smearplot(), gl.tree.nj()

Examples

if (requireNamespace("dendextend", quietly = TRUE)) {
  gl <- testset.gl[1:10, ]
  D <- dist(as.matrix(gl))
  gl.plot.heatmap(D, x = gl)
  D2 <- gl.dist.pop(possums.gl)
  gl.plot.heatmap(D2)
}

D3 <- gl.fixed.diff(testset.gl)
gl.plot.heatmap(D3)


dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.