plot_heatmap | R Documentation |
Create a heatmap with tracks and dendrograms from any matrix.
plot_heatmap(
mtx,
grid = list(label = "Grid Value", colors = "imola"),
tracks = NULL,
label = TRUE,
label_size = NULL,
rescale = "none",
trees = TRUE,
clust = "complete",
dist = "euclidean",
asp = 1,
tree_height = 10,
track_height = 10,
legend = "right",
title = NULL,
xlab.angle = "auto",
...
)
mtx |
A numeric |
grid |
Color palette name, or a list with entries for |
tracks |
List of track definitions. See details below.
Default: |
label |
Label the matrix rows and columns. You can supply a list
or logical vector of length two to control row labels and column
labels separately, for example
|
label_size |
The font size to use for the row and column labels. You
can supply a numeric vector of length two to control row label sizes
and column label sizes separately, for example
|
rescale |
Rescale rows or columns to all have a common min/max.
Options: |
trees |
Draw a dendrogram for rows (left) and columns (top). You can
supply a list or logical vector of length two to control the row tree
and column tree separately, for example
|
clust |
Clustering algorithm for reordering the rows and columns by
similarity. You can supply a list or character vector of length two to
control the row and column clustering separately, for example
Default: |
dist |
Distance algorithm to use when reordering the rows and columns
by similarity. You can supply a list or character vector of length
two to control the row and column clustering separately, for example
Default: |
asp |
Aspect ratio (height/width) for entire grid.
Default: |
tree_height , track_height |
The height of the dendrogram or annotation
tracks as a percentage of the overall grid size. Use a numeric vector
of length two to assign |
legend |
Where to place the legend. Options are: |
title |
Plot title. Default: |
xlab.angle |
Angle of the labels at the bottom of the plot.
Options are |
... |
Additional arguments to pass on to ggplot2::theme(). |
A ggplot2
plot. The computed data points and ggplot
command are available as $data
and $code
,
respectively.
One or more colored tracks can be placed on the left and/or top of the heatmap grid to visualize associated metadata values.
## Categorical ---------------------------- cat_vals <- sample(c("Male", "Female"), 10, replace = TRUE) tracks <- list('Sex' = cat_vals) tracks <- list('Sex' = list(values = cat_vals, colors = "bright")) tracks <- list('Sex' = list( values = cat_vals, colors = c('Male' = "blue", 'Female' = "red")) ) ## Numeric -------------------------------- num_vals <- sample(25:40, 10, replace = TRUE) tracks <- list('Age' = num_vals) tracks <- list('Age' = list(values = num_vals, colors = "greens")) tracks <- list('Age' = list(values = num_vals, range = c(0,50))) tracks <- list('Age' = list( label = "Age (Years)", values = num_vals, colors = c("azure", "darkblue", "darkorchid") )) ## Multiple Tracks ------------------------ tracks <- list('Sex' = cat_vals, 'Age' = num_vals) tracks <- list( list(label = "Sex", values = cat_vals, colors = "bright"), list(label = "Age", values = num_vals, colors = "greens") ) mtx <- matrix(sample(1:50), ncol = 10) dimnames(mtx) <- list(letters[1:5], LETTERS[1:10]) plot_heatmap(mtx = mtx, tracks = tracks)
The following entries in the track definitions are understood:
values
- The metadata values. When unnamed, order must match matrix.
range
- The c(min,max) to use for scale values.
label
- Label for this track. Defaults to the name of this list element.
side
- Options are "top"
(default) or "left"
.
colors
- A pre-defined palette name or custom set of colors to map to.
na.color
- The color to use for NA
values.
bins
- Bin a gradient into this many bins/steps.
guide
- A list of arguments for guide_colorbar() or guide_legend().
All built-in color palettes are colorblind-friendly. See Mapping Metadata to Aesthetics for images of the palettes.
Categorical palette names: "okabe"
, "carto"
, "r4"
,
"polychrome"
, "tol"
, "bright"
, "light"
,
"muted"
, "vibrant"
, "tableau"
, "classic"
,
"alphabet"
, "tableau20"
, "kelly"
, and "fishy"
.
Numeric palette names: "reds"
, "oranges"
, "greens"
,
"purples"
, "grays"
, "acton"
, "bamako"
,
"batlow"
, "bilbao"
, "buda"
, "davos"
,
"devon"
, "grayC"
, "hawaii"
, "imola"
,
"lajolla"
, "lapaz"
, "nuuk"
, "oslo"
,
"tokyo"
, "turku"
, "bam"
, "berlin"
,
"broc"
, "cork"
, "lisbon"
, "roma"
,
"tofino"
, "vanimo"
, and "vik"
.
Other visualization:
adiv_boxplot()
,
adiv_corrplot()
,
bdiv_boxplot()
,
bdiv_corrplot()
,
bdiv_heatmap()
,
bdiv_ord_plot()
,
rare_corrplot()
,
rare_multiplot()
,
rare_stacked()
,
stats_boxplot()
,
stats_corrplot()
,
taxa_boxplot()
,
taxa_corrplot()
,
taxa_heatmap()
,
taxa_stacked()
library(rbiom)
set.seed(123)
mtx <- matrix(runif(5*8), nrow = 5, dimnames = list(LETTERS[1:5], letters[1:8]))
plot_heatmap(mtx)
plot_heatmap(mtx, grid="oranges")
plot_heatmap(mtx, grid=list(colors = "oranges", label = "Some %", bins = 5))
tracks <- list(
'Number' = sample(1:ncol(mtx)),
'Person' = list(
values = factor(sample(c("Alice", "Bob"), ncol(mtx), TRUE)),
colors = c('Alice' = "purple", 'Bob' = "darkcyan") ),
'State' = list(
side = "left",
values = sample(c("TX", "OR", "WA"), nrow(mtx), TRUE),
colors = "bright" )
)
plot_heatmap(mtx, tracks=tracks)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.