ggheatmap: Plot heatmap.

View source: R/ggheatmap.R

ggheatmapR Documentation

Plot heatmap.

Description

Given a data frame, a matrix or a list of matrices this function visualizes the given data by a heatmap utilizing ggplot2.

Usage

ggheatmap(x, id.vars = c("Var1", "Var2"), value.name = "value",
  show.diag = TRUE, type = "complete", range = NULL,
  show.values = FALSE, value.size = 1.5, value.color = "white",
  digits = 1L)

Arguments

x

[matrix | list of matrices | data.frame]
Data frame, matrix or a list of matrices.

id.vars

[character(2)]
Only relevant if x is of type data.frame. Character vector of length two indicating the column names of x which serve as id variables. Defaults to “id.vars = c("Var1", "Var2")”.

value.name

[character(1)]
Name for the values represented by the matrix. Internally, the matrix is transformed into a data.frame via melt in order to obtain a format which may be processed by ggplot easily. Default is “value”.

show.diag

[logical(1)]
If x is a square matrix, e.g., a correlation matrix, or x is a list of square matrices this argument controls whether the diagonal elements should be visualized. Default is TRUE.

type

[character(1)]|cr Values “lower.tri” and “upper.tri” respectively display the lower or upper triangular matrix only. Option “complete” is the default and displays all values. This option is ignored if x is already a data frame or the passed matrix/matrices are not square.

range

[numeric(2)]
Possibility to cap values below range[1] and above range[2]. Defaults to NULL, i.e., no capping at all.

show.values

[logical(1L)]
Should the values be printed within the heatmap cells? Default is FALSE.

value.size

[numeric(1)]
Size of the printed values. Only relevant if show.values is TRUE. Default is 1.5.

value.color

[character(1)]
Color of text in cells. Only relevant if show.values is TRUE. Default is “white”.

digits

[integer(1)]
Integer indicating the number of decimal places to be used if show.values is TRUE.

Details

If a data.frame is passed it needs to be in long format as expected by ggplot2. If a matrix is passed it is transformed internally into long format. In case a list of matrices is passed all those matrices are converted into long format and distinguished by the names of the list components. In the latter case a single ggplot object is produced adopting facets to split by matrix.

Value

[ggplot] ggplot object.

Examples

# simulate two (correlation) matrizes
x = matrix(runif(100), ncol = 10)
y = matrix(runif(100), ncol = 10)

# matrix x in ggplot2-friendly long format
x.df = reshape2::melt(x)

## Not run: 
# Single heatmap with default settings
pl = plotHeatmap(x.df)

# Show values and display lower triangular matrix only
pl = plotHeatmap(x, show.values = TRUE, type = "lower.tri", show.diag = FALSE)

# Now we omit value outside the interval [10, 80]
pl = plotHeatmap(x, range = c(10, 80))

# Two heatmaps side by side
pl = plotHeatmap(list(x, y), value.name = "Similarity")

# Same as above with custom names
pl = plotHeatmap(list(MatrixX = x, MatrixY = y), value.name = "Similarity")


## End(Not run)

jakobbossek/ggheatmap documentation built on May 14, 2022, 3:33 a.m.