Description Usage Arguments Author(s) Examples
Heatmap
displays a heatmap at a arbitary level of a tree.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | Heatmap(
hm_data,
cell_line_color = NA,
cell_line_size = 0,
column_order = NULL,
column_split = NULL,
column_split_gap = 0.2,
column_split_label = NULL,
column_split_label_fontface = "bold",
column_split_label_color = "black",
column_split_label_size = 3,
column_split_label_angle = 0,
column_split_label_offset_x = 0,
column_split_label_offset_y = 2,
column_split_label_hjust = 0.5,
row_order = NULL,
row_split = NULL,
row_split_gap = 0.2,
row_split_label = NULL,
row_split_label_fontface = "bold",
row_split_label_color = "black",
row_split_label_size = 3,
row_split_label_angle = 0,
row_split_label_offset_x = 0,
row_split_label_offset_y = 2,
row_split_label_hjust = 0.5,
column_anno = NULL,
column_anno_size = 1,
column_anno_color = NULL,
column_anno_gap = 0.1,
legend_title_hm = "Expression",
legend_title_column_anno = "group",
show_colnames = FALSE,
colnames_position = "top",
colnames_angle = 0,
colnames_offset_x = 0,
colnames_offset_y = 0,
colnames_size = 4,
colnames_hjust = 0.5,
show_rownames = FALSE,
rownames_position = "right",
rownames_angle = 0,
rownames_offset_x = 0,
rownames_offset_y = 0,
rownames_size = 4,
rownames_hjust = 0.5,
rownames_label = NULL,
rownames_color = "black",
show_title = FALSE,
title_hm = "First heatmap",
title_fontface = "bold",
title_color = "black",
title_size = 3,
title_angle = 0,
title_offset_x = 0,
title_offset_y = 2,
title_hjust = 0.5,
cluster_column = TRUE,
cluster_row = TRUE,
dist_method = "euclidean",
hclust_method = "ave",
show_row_tree = TRUE
)
|
hm_data |
A data frame. Data to plot heatmap. Its rownames should be able to match to nodes of the tree. |
cell_line_color |
A color for the lines among cells of the heatmap. The default is NA. |
cell_line_size |
A value to specify the size of lines among cells of the heatmap. The default is 0. |
column_order |
A character vector that includes the column name of hm_data to specify the display order of the heatmap. It's ignored when column_split is provided. |
column_split |
A named character vector that gives the group information about columns to split the heatmap. It's named by the colnames of hm_data. |
column_split_gap |
A numeric value to specify the gap between the columns of heatmap that are split. |
column_split_label |
A named character vector to label the column split. It's named by the value or level of the column_split. |
column_split_label_fontface |
The fontface of the labels of the column split. The default is "bold". |
column_split_label_color |
The color of the the labels of the column split. The default is "black". |
column_split_label_size |
The size of the the labels of the column split. The default is 3. |
column_split_label_angle |
The angle of the the labels of the column split. The default is 0. |
column_split_label_offset_x |
A numeric value to shift the labels of the column split along x-axis. The defaut is 0. |
column_split_label_offset_y |
A numeric value to shift the labels of the column split along y-axis. The defaut is 2. |
column_split_label_hjust |
The hjust for the labels of the column split: 0 (left aligned); 0.5 (centered); 1 (right aligned). The default is 0.5 |
row_order |
A character vector that includes the column name of hm_data to specify the display order of the heatmap. It's ignored when row_split is provided. |
row_split |
A named character vector that gives the group information about columns to split the heatmap. It's named by the colnames of hm_data. |
row_split_gap |
A numeric value to specify the gap between the columns of heatmap that are split. |
row_split_label |
A named character vector to label the column split. It's named by the value or level of the row_split. |
row_split_label_fontface |
The fontface of the labels of the column split. The default is "bold". |
row_split_label_color |
The color of the the labels of the column split. The default is "black". |
row_split_label_size |
The size of the the labels of the column split. The default is 3. |
row_split_label_angle |
The angle of the the labels of the column split. The default is 0. |
row_split_label_offset_x |
A numeric value to shift the labels of the column split along x-axis. The defaut is 0. |
row_split_label_offset_y |
A numeric value to shift the labels of the column split along y-axis. The defaut is 2. |
row_split_label_hjust |
The hjust for the labels of the column split: 0 (left aligned); 0.5 (centered); 1 (right aligned). The default is 0.5 |
column_anno |
A named vector to specify labels that are used to annotate columns of heatmap. |
column_anno_size |
A numeric value to specify the size of the annotation bar |
column_anno_color |
A named vector to specify colors that are used to annotate columns of heatmap. |
column_anno_gap |
A numeric value to specify the gap between the column annotation bar and the heatmap. |
legend_title_hm |
The legend title of the heatmap. |
legend_title_column_anno |
The legend title of the column annotation. |
show_colnames |
A logical value to specify whether column names should be displayed. The default is FALSE. |
colnames_position |
The position of column names, "top" or "bottom". |
colnames_angle |
A numeric value. The angle of column names. |
colnames_offset_x |
A numeric value to shift column names on x-axis. The defaut is 0. |
colnames_offset_y |
A numeric value to shift column names on y-axis. The defaut is 0. |
colnames_size |
A numeric value to specify the size of column names. |
colnames_hjust |
The hjust for column names: 0 (left aligned); 0.5 (centered); 1 (right aligned). |
show_rownames |
A logical value to specify whether row names should be displayed. The default is FALSE. |
rownames_position |
"right" or "left". |
rownames_angle |
A numeric value. The angle of row names. |
rownames_offset_x |
A numeric value to shift row names on x-axis. The defaut is 0. |
rownames_offset_y |
A numeric value to shift row names on y-axis. The defaut is 0. |
rownames_size |
A numeric value to specify the size of row names. |
rownames_hjust |
The hjust for row names: 0 (left aligned); 0.5 (centered); 1 (right aligned). |
rownames_label |
A named vector to annotate the rows of heatmap instead the row names of hm_data. |
rownames_color |
A color for row names. |
show_title |
A logical value to specify whether the title should be displayed. The default is FALSE. |
title_hm |
The title of heatmap |
title_fontface |
The fontface of the title. The default is "bold". |
title_color |
The color of the title. The default is "black". |
title_size |
The size of the title. The default is 3. |
title_angle |
The angle of the title. The default is 0. |
title_offset_x |
A numeric value to shift title along x-axis. The defaut is 0. |
title_offset_y |
A numeric value to shift title along y-axis. The defaut is 2. |
title_hjust |
The hjust for title: 0 (left aligned); 0.5 (centered); 1 (right aligned). The default is 0.5 |
cluster_column |
A logical value, TRUE or FALSE. It specifies whether columns of the heatmap should be ordered by similarity. The default is TRUE. This is ignored when column_order is given. |
cluster_row |
A logical value, TRUE or FALSE. It specifies whether columns of the heatmap should be ordered by similarity. The default is TRUE. This is ignored when column_order is given. |
dist_method |
See method in |
hclust_method |
See method in |
show_row_tree |
TRUE or FALSE. Default is TRUE. If FALSE, the figure
provied in |
Ruizhu Huang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | library(TreeSummarizedExperiment)
library(ggtree)
library(ggplot2)
library(scales)
data(tinyTree)
p1 <- c(rep(0.1/3, 3), rep(0.4/2, 2), rep(0.1, 5))
p2 <- c(rep(0.4/3, 3), rep(0.1/2, 2), rep(0.1, 5))
set.seed(1)
ct0 <- cbind(rmultinom(n = 5, size = 50, prob = p1),
rmultinom(n = 5, size =50, prob = p2))
colnames(ct0) <- paste("S", 1:10, sep = "")
rownames(ct0) <- transNode(tree = tinyTree, node = 1:10)
oo <- sample(1:10)
ct0 <- ct0[, oo]
ct <- rbind(colSums(ct0[1:3, ]),
colSums(ct0[4:5, ]),
ct0[6:10, ])
colnames(ct) <- paste("S", 1:10, sep = "")
rownames(ct) <- transNode(tree = tinyTree, node = c(13, 18, 6:10))
# prepare the tree figure
tree_fig <- ggtree(tinyTree,
branch.length = "none",
layout = "rectangular", open.angle = 100) +
#geom_text2(aes(label = label)) +
geom_hilight(node = 18, fill = "orange", alpha = 0.3) +
geom_hilight(node = 13, fill = "blue", alpha = 0.3)
# figure 0
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig, hm_data = ct0[, oo])
# figure 1
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig, hm_data = ct)
# figure 2: order column by similarity
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig,
hm_data = ct, cluster_column = TRUE)
# figure 3: split columns
col_split <- ifelse(colnames(ct) %in% paste0("S", 1:5),
"A", "B")
names(col_split) <- colnames(ct)
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig,
hm_data = ct, cluster_column = TRUE,
column_split = col_split)
# figure 4: annotate columns
col_anno <- col_split
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig,
hm_data = ct, cluster_column = TRUE,
column_split = col_split,
column_anno = col_anno,
column_anno_gap = 0.5)
# figure 5: change annotation colors
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig,
hm_data = ct, cluster_column = TRUE,
column_split = col_split,
column_anno = col_anno,
column_anno_gap = 0.6,
column_anno_color = c("A" = "red", "B"= "blue"))
# figure 6: add colnames
TreeHeatmap(tree = tinyTree, tree_fig = tree_fig,
hm_data = ct, cluster_column = TRUE,
column_split = col_split,
column_anno = col_anno,
column_anno_gap = 0.6,
column_anno_color = c("A" = "red", "B"= "blue"),
show_colnames = TRUE,
colnames_position = "bottom",
colnames_angle = 90, colnames_size = 2,
colnames_offset_y = -0.2)
# figure 7: add title
fig <- TreeHeatmap(tree = tinyTree, tree_fig = tree_fig,
hm_data = ct, cluster_column = TRUE,
column_split = col_split,
column_anno = col_anno,
column_anno_gap = 0.6,
column_anno_color = c("A" = "red", "B"= "blue"),
show_colnames = TRUE,
colnames_position = "bottom",
colnames_angle = 90, colnames_size = 2,
colnames_offset_y = -0.2,
show_title = TRUE,
title_offset_y = 1.5,
title_color = "blue")
fig
# use expand_limits to display the missing part of row names
(fig <- fig + expand_limits(x = c(0, 15)))
# change colors
fig +
scale_fill_viridis_c(option = "D")
fig +
scale_fill_gradientn(colours = c("blue","yellow","red"),
values = scales::rescale(c(5, 8, 10)),
guide = "colorbar", limits=c(5, 10))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.