Package 'heatmapFlex'

Title: Tools to Generate Flexible Heatmaps
Description: A set of tools supporting more flexible heatmaps. The graphics is grid-like using the old graphics system. The main function is heatmap.n2(), which is a wrapper around the various functions constructing individual parts of the heatmap, like sidebars, picket plots, legends etc. The function supports zooming and splitting, i.e., having (unlimited) small heatmaps underneath each other in one plot deriving from the same data set, e.g., clustered and ordered by a supervised clustering method.
Authors: Vidal Fey [aut, cre], Henri Sara [aut]
Maintainer: Vidal Fey <[email protected]>
License: GPL-3
Version: 0.1.2
Built: 2024-11-04 06:39:47 UTC
Source: CRAN

Help Index


Function to draw a heatmap based on prepared "display list" (dl)

Description

Normally, draw_heatmap is called from within heatmap.n2 (if argument plot is TRUE which is the default) but if that is not desired, e.g., for zooming, it can be called separately.

Usage

draw_heatmap(dl, set.oma = TRUE, ...)

Arguments

dl

(list). The "display list": A list with all parameters needed for plotting the heatmap.

set.oma

(logical). Should the outer margins be set to optimized values? Defaults to TRUE.

...

(list). Additional parameters passed to plot.

Value

Invisibly returns a list with graphical parameters. But mainly the function is called for its side-effect of generating a plot.

See Also

par


Main heatmap function

Description

This is the main function to be called be end users. It accepts a numeric matrix and draws a heatmap.

Usage

heatmap.n2(
  x,
  main = "Heatmap",
  ...,
  na.color = "gray80",
  sidebars = NULL,
  picketdata = NULL,
  r.cex = 1,
  c.cex = 1,
  titleheight = lcm(1.2),
  dendroheight = lcm(3),
  dendrowidth = lcm(3),
  labelheight = lcm(1),
  labelwidth = lcm(1),
  picketheight = 0.4,
  sidebarwidth = lcm(1),
  sidebar.cex = 1,
  colorkeylabels = FALSE,
  legendcorner = "bottomleft",
  plot = TRUE,
  factorpalettefn = "Pastel1",
  add.sig = FALSE,
  pv = NULL,
  order_list = TRUE,
  genes2highl = NULL
)

Arguments

x

(numeric). Numeric matrix.

main

(character). Main plot title.

...

Additional arguments passed to prepare_heatmap_data2.

na.color

(character). Colour code or name used for missing values. Defaults to gray80.

sidebars

(list). List of data frames for each of the four sides of the heatmap ("bottom", "left", "top", "right"). Each column in the data frame represents some statistics or other numerical variable describing the rows or columns of the data matrix.

picketdata

(data.frame or numeric). Usually a data frame with columns consisting of 0 and 1. The columns describe categories that the samples (rows in the picketdata) belong to, such as sex or a health stage. The categories must be binary, so the data frame would for example have two rows, 'female' and 'male', and the rows (=samples) are coded with 1 (=TRUE) and 0 (=FALSE). See picketPlot for a description of the general purpose of a picket plot.

r.cex

(numeric). Font size for row labels.

c.cex

(numeric). Font size for column labels.

titleheight

(numeric or lcm(numeric)). Relative or absolute height (using lcm, see layout) of the plot title.

dendroheight

(numeric or lcm(numeric)). Relative or absolute height (using lcm, see layout) of the dendrogram.

dendrowidth

(numeric or lcm(numeric)). Relative or absolute width (using lcm, see layout) of the dendrogram.

labelheight

(numeric or lcm(numeric)). Relative or absolute height (using lcm, see layout) of the labels.

labelwidth

(numeric or lcm(numeric)). Relative or absolute width (using lcm, see layout) of the labels.

picketheight

(numeric or lcm(numeric)). Relative or absolute height (using lcm, see layout) of the picket plots.

sidebarwidth

(numeric or lcm(numeric)). Relative or absolute width (using lcm, see layout) of the sidebars.

sidebar.cex

(numeric). Font size for sidebar labels.

colorkeylabels

(logical). Should colour key labels be added?

legendcorner

(character). Position of the legend.

plot

(logical). Draw the plot? Defaults to TRUE.

factorpalettefn

(character). Name of the colour palette.

add.sig

(logical). Should significance asterixes be drawn?

pv

(numeric). Matrix of the same dimensions as x with P-Values for correlation significance.

order_list

(logical). Should the order of the correlation matrix be reversed? Meaningful if the order of input variables should be preserved because image turns the input matrix.

genes2highl

(character). Vector of gene symbols (or whatever labels are used) to be highlighted. If not NULL will draw a semi-transparent rectangle around the labels and rows or columns in the heatmap labels.

Details

The result can be used for zooming. For simple basic cases, picketvar can be given directly. Factor sidebars are supported, but legends are only shown for the first two. Arguments that will be passed on the prepare_heatmap_data2:

labRow (character). Custom row labels
labCol (character). Custom column labels
Rowv (dendrogram or integer). Custom dendrogram object or integer vector giving the ordering index for rows
Colv (dendrogram or integer). Custom dendrogram object or integer vector giving the ordering index for columns
reorder (logical). Boolean of length 2 for rows and columns. Should rows and/or columns be reordered according to Rowv/Colv
distfun (function). Distance function. Defaults to dist
hclustfun (function). Hierarchical clustering function. Defaults to hclust
rowMembers (character). Group vector to split rows by
colMembers (character). Group vector to split columns by
spacer (integer). Length 1 integer used as spacer to separate groups (see rowMembers/colMembers). Defaults to 1
scale (character). One of "row", "column" or "none": By which dimension should data be scaled? Defaults to "none"
trim (numeric). Value to "cut off" data distribution. Values and both ends of the distribution, larger or smaller, respectively, will be made equal to +/-trim. Defaults to NULL, no trimming
zlim (numeric). Value to set the ranges for plotting x and y values. Supports both symmetrical (with default NULL) and asymmetrical (NA) automatic zlim. Used for zooming
col (character) Name (acronym) of the colour palette to use. Can be one of "RdBkGn" (c("green", "black", "red")), "BuYl" (c("blue", "yellow")), "BuWtRd" (c("blue", "white", "red")) or a valid name used by brewer.pal. Defaults to NULL which will set "RdBkGn"
filter (integer or logical.) For filtering rows/columns: TRUE (=1.0) = remove rows/columns with only NAs, 0.5 = remove if >= 50 per cent NAs, etc. Defaults to c(TRUE, TRUE)

Value

In addition to its side-effect of plotting the heatmap (if plot is TRUE, which is the default), the function will invisibly returns the prepared "display list", a list of all parts of the heatmap used by hlayout() to actually draw the final heatmap.

See Also

layout

brewer.pal

colorRampPalette

dist

hclust

picketPlot

Examples

# Generate a random 10x10 matrix and plot it using default values
mat <- matrix(rnorm(100), nrow = 10)
heatmap.n2(mat)

# Generate a random 10x10 matrix with two distinct sets, order it using
# default clustering methods, split it into each two groups along both rows
# and columns and adjust colour palette and dendrogram dimensions:
mat <- matrix(c(rnorm(50, mean = 1), rnorm(50, mean = -1)), nrow = 10)
heatmap.n2(mat, col = "BuWtRd", rowMembers=rep(1:2, each=5),
    colMembers=rep(1:2, each=5), labRow=paste0("gene-", 1:10),
    labCol=paste0(c("A", "B"), rep(1:5, 2)), r.cex=0.8,
    dendroheight = lcm(2.2), dendrowidth = lcm(2.4))

Tools to Generate Flexible Heatmaps

Description

The package has a number of tools supporting more flexible heatmaps. The graphics is grid-like using the old graphics system. The main function is heatmap.n2, which is a wrapper around the various functions constructing individual parts of the heatmap, like sidebars, picket plots, legends etc. The function supports zooming and splitting, i.e., having (unlimited) small heatmaps underneath each other in one plot deriving from the same data set, e.g., clustered and ordered by a supervised clustering method.

Details

Package: heatmapFlex
Type: Package
Initial version: 0.1-0
Created: 2021-08-11
License: GPL-3
LazyLoad: yes

Author(s)

Vidal Fey <[email protected]>, Henri Sara <[email protected]> Maintainer: Vidal Fey <[email protected]>


Function to prepare data for a heatmap: scaling, dendrograms, ...

Description

Function to prepare data for a heatmap: scaling, dendrograms, ...

Usage

prepare_heatmap_data2(
  x,
  labRow = NA,
  labCol = NA,
  Rowv = NULL,
  Colv = NULL,
  reorder = c(TRUE, TRUE),
  distfun = dist,
  hclustfun = hclust,
  rowMembers = NULL,
  colMembers = NULL,
  spacer = 1,
  scale = "none",
  trim = NULL,
  zlim = NULL,
  col = NULL,
  filter = c(TRUE, TRUE),
  add.sig = FALSE,
  pv = NULL
)

Arguments

x

(numeric). Numeric matrix.

labRow

(character). Custom row labels.

labCol

(character). Custom column labels.

Rowv

(dendrogram or integer). Custom dendrogram object or integer vector giving the ordering index for rows.

Colv

(dendrogram or integer). Custom dendrogram object or integer vector giving the ordering index for columns

reorder

(logical). Boolean of length 2 for rows and columns. Should rows and/or columns be reordered according to Rowv/Colv?

distfun

(function). Distance function. Defaults to dist.

hclustfun

(function). Hierarchical clustering function. Defaults to hclust.

rowMembers

(character). Group vector to split rows by.

colMembers

(character). Group vector to split columns by.

spacer

(integer). Length 1 integer used as spacer to separate groups (see rowMembers/colMembers). Defaults to 1.

scale

(character). One of "row", "column" or "none": By which dimension should data be scaled? Defaults to "none".

trim

(numeric). Value to "cut off" data distribution. Values and both ends of the distribution, larger or smaller, respectively, will be made equal to +/-trim. Defaults to NULL, no trimming.

zlim

(numeric). Value to set the ranges for plotting x and y values. Supports both symmetrical (with default NULL) and asymmetrical (NA) automatic zlim. Used for zooming.

col

(character) Name (acronym) of the colour palette to use. Can be one of "RdBkGn" (c("green", "black", "red")), "BuYl" (c("blue", "yellow")), "BuWtRd" (c("blue", "white", "red")) or a valid name used by brewer.pal. Defaults to NULL which will set "RdBkGn".

filter

(integer or logical.) For filtering rows/columns: TRUE (=1.0) = remove rows/columns with only NAs, 0.5 = remove if >= 50 per cent NAs, etc. Defaults to c(TRUE, TRUE).

add.sig

(logical). Should significance asterixes be drawn?

pv

(numeric). Matrix of the same dimensions as x with P-Values for correlation significance.

Details

This function is used by heatmap.n2 and should not be called bu the user directly. It is only documented because its arguments are passed by the main function when given there.


Function to zoom into an already drawn heatmap

Description

After the heatmap was drawn in a screen device such as X11, windows and quartz it can be zoomed by using the mouse.

Usage

zoom_heatmap(dl, ...)

Arguments

dl

(list). The "display list": A list with all parameters needed for plotting the heatmap.

...

(list). Additional parameters passed to draw_heatmap (and eventually to plot).

Value

Invisibly returns a list with graphical parameters but is mainly called for its side-effect of drawing a zoomed plot.

See Also

locator