熱圖列表
ComplexHeatmap包的主要特點是它可以水平或垂直連接熱圖和注釋列表,我們可以將各種信息來源進行可視化關(guān)聯(lián)。在本章中,我們主要介紹水平串聯(lián)(在分析中使用頻率較高)后面也展示了一些垂直串聯(lián)的例子。水平和垂直串聯(lián)在語法上是基本相似的。
對于水平串聯(lián),所有熱圖和注釋的行數(shù)應該相同。我們首先介紹熱圖的串聯(lián),然后我們將展示如何將熱圖與注釋串聯(lián)。
在下面例子中,有三個矩陣,其中第三個是一個熱圖向量,它將被轉(zhuǎn)換為一列矩陣。當您連接熱圖列表時,一列熱圖有時很有用,它可以顯示例如每行的注釋或每行的一些分數(shù)。例如,如果行是基因,則基因的類型(即蛋白質(zhì)編碼與否)可以表示為一列字符矩陣,差異表達分析的p值或倍數(shù)變化可以表示為一列數(shù)字矩陣,并連接到主熱圖中。
set.seed(123)
mat1 = matrix(rnorm(80, 2), 8, 10)
mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
rownames(mat1) = paste0("R", 1:12)
colnames(mat1) = paste0("C", 1:10)
mat2 = matrix(runif(60, max = 3, min = 1), 6, 10)
mat2 = rbind(mat2, matrix(runif(60, max = 2, min = 0), 6, 10))
rownames(mat2) = paste0("R", 1:12)
colnames(mat2) = paste0("C", 1:10)
le = sample(letters[1:3], 12, replace = TRUE)
names(le) = paste0("R", 1:12)
ind = sample(12, 12)
mat1 = mat1[ind, ]
mat2 = mat2[ind, ]
le = le[ind]
要連接熱圖,只需使用+運算符。
ht1 = Heatmap(mat1, name = "rnorm")
ht2 = Heatmap(mat2, name = "runif")
ht3 = Heatmap(le, name = "letters")
ht1 + ht2 + ht3

在默認模式下,第二個熱圖中的樹狀圖將被刪除,行順序?qū)⑴c第一個相同。前兩個熱圖的行名稱也被刪除。
連接的返回值是一個HeatmapList對象。直接打印ht_list將調(diào)用draw()具有默認設(shè)置的方法。通過顯式調(diào)用draw() 方法,您可以對熱圖列表進行更多控制。
ht_list = ht1 + ht2 + ht3
class(ht_list)
## [1] "HeatmapList"
## attr(,"package")
## [1] "ComplexHeatmap"
您可以將任意數(shù)量的熱圖附加到熱圖列表中。您也可以將熱圖列表附加到熱圖列表。
# code only for demonstration
ht1 + ht_list
ht_list + ht1
ht_list + ht_list
當用戶希望通過for循環(huán)構(gòu)建熱圖列表時,NULL可以添加到熱圖列表中。
# code only for demonstration
ht_list = NULL ## Heatmap(...) + NULL gives you a HeatmapList object
for(s in sth) {
ht_list = ht_list + Heatmap(...)
}
您還可以向熱圖列表中添加熱圖注釋,后續(xù)介紹。
4.1 標題
熱圖列表也有標題,就像覆蓋所有熱圖的全局標題。row_title和column_title應該在draw() 函數(shù)中設(shè)置。
從以下示例中,我們?yōu)槊總€熱圖設(shè)置了不同的顏色以使其可區(qū)分。
col_rnorm = colorRamp2(c(-3, 0, 3), c("green", "white", "red"))
col_runif = colorRamp2(c(0, 3), c("white", "orange"))
col_letters = c("a" = "pink", "b" = "purple", "c" = "blue")
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm,
row_title = "Heatmap 1", column_title = "Heatmap 1")
ht2 = Heatmap(mat2, name = "runif", col = col_runif,
row_title = "Heatmap 2", column_title = "Heatmap 2")
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list, row_title = "Three heatmaps, row title", row_title_gp = gpar(col = "red"),
column_title = "Three heatmaps, column title", column_title_gp = gpar(fontsize = 16))

拓展 可以用gt_render()來構(gòu)造復雜的文本。
4.2 熱圖的大小
某些熱圖的寬度可以設(shè)置為絕對單位。注意width 控制熱圖主體的寬度。
ht2 = Heatmap(mat2, name = "runif", col = col_runif, width = unit(4, "cm"))
ht3 = Heatmap(le, name = "letters", col = col_letters, width = unit(5, "mm"))
ht1 + ht2 + ht3

所有熱圖的寬度都可以設(shè)置為絕對單位。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, width = unit(4, "cm"))
ht2 = Heatmap(mat2, name = "runif", col = col_runif, width = unit(6, "cm"))
ht3 = Heatmap(le, name = "letters", col = col_letters, width = unit(1, "cm"))
ht1 + ht2 + ht3

如果width是數(shù)字,則將其轉(zhuǎn)換為null單位。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, width = 6)
ht2 = Heatmap(mat2, name = "runif", col = col_runif, width = 4)
ht3 = Heatmap(le, name = "letters", col = col_letters, width = 1)
ht1 + ht2 + ht3

heatmap_width 也可以控制熱圖的寬度,但它是熱圖主體加上熱圖組件的總寬度。
4.3 熱圖之間的差距
ht_gap控制熱圖之間的空間。該值可以是單個單位或單位向量。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list, ht_gap = unit(1, "cm"))

draw(ht_list, ht_gap = unit(c(3, 10), "mm"))

4.4 主熱圖自動調(diào)整
熱圖列表中總是有一個主熱圖來控制全局行排序。所有其它熱圖都會根據(jù)主熱圖中的設(shè)置自動調(diào)整。對于這些非主熱圖,則進行如下調(diào)整:
- 不執(zhí)行行聚類,它們都采用主熱圖的行排序。
- 行標題被刪除。
- 如果主熱圖按行拆分,所有其他熱圖也將按與主熱圖相同的級別拆分。
- 主熱圖的高度作為所有熱圖的高度。
默認情況下,第一個熱圖被作為主熱圖。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, row_km = 2)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht2 + ht1 + ht3 # ht2 is the main heatmap and row_km in ht1 is ignored

主熱圖可以通過main_heatmap參數(shù)指定。該值可以是數(shù)字索引或熱圖的名稱(需要在創(chuàng)建Heatmap對象時設(shè)置熱圖名稱)。在下面的示例中,雖然ht1是第二個熱圖,但我們可以將其設(shè)置為主熱圖。
ht_list = ht2 + ht1 + ht3
draw(ht_list, main_heatmap = "rnorm")

默認情況下,樹狀圖和行標題繪制在主熱圖旁邊,只是為了強調(diào)聚類或拆分是從主熱圖而不是其他熱圖計算的。但是,主熱圖的樹狀圖和行標題的位置可以由draw()函數(shù)中row_dend_side和row_sub_title_side控制 。
ht_list = ht2 + ht1 + ht3
draw(ht_list, main_heatmap = "rnorm", row_dend_side = "right", row_sub_title_side = "left")

類似地,如果主熱圖中沒有行聚類,則所有其他熱圖也不會聚類。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, cluster_rows = FALSE)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht1 + ht2 + ht3

您可能已經(jīng)觀察到,熱圖之間的所有行名稱都從圖中刪除。您可以通過設(shè)置來顯示它們auto_adjust = FALSE。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list, auto_adjust = FALSE)

4.5 draw()函數(shù)中控制主熱圖
主熱圖的設(shè)置可以在主Heatmap() 函數(shù)中控制。為方便起見,draw()可以直接設(shè)置熱圖的行屬性. 如果設(shè)置了draw()這些屬性中的一些,主熱圖中的相應設(shè)置將被Heatmap()覆蓋。
在draw()功能上,以下是控制所有熱圖的行順序主要熱圖設(shè)置。
cluster_rowsclustering_distance_rowsclustering_method_rowsrow_dend_widthshow_row_dendrow_dend_reorderrow_dend_gprow_order
以下控制行切片設(shè)置。
row_gaprow_kmrow_km_repeatsrow_split
以下控制熱圖高度設(shè)置。
heightheatmap_height
在以下示例中,在draw()中的row_km = 2, cluster_rows = FALSE 將覆蓋 ht1的設(shè)置。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, row_km = 2, cluster_rows = FALSE)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list, row_km = 1, row_split = le, cluster_rows = TRUE)

4.6 作為組件調(diào)整注釋
如果熱圖列表中的一些熱圖有注釋,在大多數(shù)情況下,不同熱圖的熱圖注釋的高度是不同的。熱圖注釋會自動調(diào)整,這個調(diào)整也會涉及到樹狀圖的調(diào)整。
通常,簡單注釋的大小不會在調(diào)整中發(fā)生變化。在以下示例中,調(diào)整了第二個熱圖的樹狀圖。請注意,您仍然可以通過設(shè)置anno_simple_size inHeatmapAnnotation()或全局設(shè)置來更改簡單注釋的大小ht_opt$anno_simple_size。
ha1 = HeatmapAnnotation(foo1 = 1:10, annotation_name_side = "left")
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, top_annotation = ha1)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht1 + ht2 + ht3

如果前兩個熱圖都有注釋,由于簡單注釋的大小保持不變,所以會調(diào)整復雜注釋的大小,使兩個熱圖注釋的總高度相同。
ha1 = HeatmapAnnotation(foo1 = 1:10, bar1 = anno_points(1:10),
annotation_name_side = "left")
ha2 = HeatmapAnnotation(bar2 = anno_barplot(1:10))
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, top_annotation = ha1)
ht2 = Heatmap(mat2, name = "runif", col = col_runif, top_annotation = ha2)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list, ht_gap = unit(c(6, 2), "mm"))

同樣,如果第一個熱圖只包含簡單的注釋,樹狀圖將被調(diào)整。
ha1 = HeatmapAnnotation(foo1 = 1:10, annotation_name_side = "left")
ha2 = HeatmapAnnotation(bar2 = anno_barplot(1:10, height = unit(2, "cm")))
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, top_annotation = ha1)
ht2 = Heatmap(mat2, name = "runif", col = col_runif, top_annotation = ha2)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list, ht_gap = unit(c(6, 2), "mm"))

如果兩個熱圖只包含簡單的注釋但數(shù)量不等,則樹狀圖將被調(diào)整。
ha1 = HeatmapAnnotation(foo1 = 1:10, annotation_name_side = "left")
ha2 = HeatmapAnnotation(bar2 = cbind(b1 = 1:10, b2 = 11:20, b3 = 21:30))
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, top_annotation = ha1)
ht2 = Heatmap(mat2, name = "runif", col = col_runif, top_annotation = ha2)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list)

如果您還想自動調(diào)整簡單注釋的大小,請在每次HeatmapAnnotation()調(diào)用simple_anno_size_adjust = TRUE即可 。
如果第二個熱圖沒有底部注釋,則第二個熱圖的列名稱將調(diào)整為直接放在熱圖主體下方。
ha1 = HeatmapAnnotation(foo1 = 1:10, bar1 = anno_points(1:10), annotation_name_side = "left")
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, bottom_annotation = ha1)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht3 = Heatmap(le, name = "letters", col = col_letters)
ht_list = ht1 + ht2 + ht3
draw(ht_list)

4.7 注釋連接
行注釋可以連接到水平熱圖列表,而不僅僅是熱圖的一個組件。請參閱以下非常簡單的示例。
ha1 = rowAnnotation(foo = 1:12, bar = anno_barplot(1:12, width = unit(4, "cm")))
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm, row_km = 2)
ht1 + ha1

foo和bar注釋可以用兩個分離的 rowAnnotation()被注釋。
Heatmap(mat1, name = "rnorm", col = col_rnorm, row_km = 2) +
rowAnnotation(foo = 1:12) +
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm")))

那我們該如何恢復mat1行名稱呢?有如下兩種方法。
- 您可以將行注釋設(shè)置為熱圖的“右注釋”,并將熱圖放在最后一個。
Heatmap(mat1, name = "rnorm", col = col_rnorm, row_km = 2, right_annotation = ha1)

# or using the previous variable
# attach_annotation(ht1, ha1, side = "right")
- 通過添加文本注釋來添加行名稱:
ht1 + ha1 + rowAnnotation(rn = anno_text(rownames(mat1),
location = unit(0, "npc"), just = "left"))

熱圖和行注釋基本上可以任意連接。
rowAnnotation(foo = 1:12) +
Heatmap(mat1, name = "rnorm", col = col_rnorm, row_km = 2) +
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm"))) +
Heatmap(mat2, name = "runif", col = col_runif)

如同前幾節(jié)所講的,行注釋也可以是熱圖組件作為左注釋或右注釋。后續(xù)將會討論了行注釋作為獨立注釋和熱圖組件的區(qū)別。
4.8 只連接注釋
連接可以在沒有任何熱圖的情況下完成。
rowAnnotation(foo = 1:12) +
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm")))

如果只有一個HeatmapAnnotation對象,則必須與NULL連接。
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm"))) + NULL

注釋列表其實也是一個HeatmapList對象。
anno_list = rowAnnotation(foo = 1:12) +
rowAnnotation(bar = anno_barplot(1:12, width = unit(4, "cm")))
class(anno_list)
## [1] "HeatmapList"
## attr(,"package")
## [1] "ComplexHeatmap"
因此,您可以將draw()函數(shù)的一些功能用于注釋列表,例如行拆分。
draw(anno_list, row_split = rep(c("A", "B"), each = 6))

在拓展知識中,展示了如何使用注釋列表來可視化多個匯總統(tǒng)計信息。
4.9 垂直串聯(lián)
熱圖和注釋(現(xiàn)在是列注釋)可以由%v%進行垂直連接。所有相關(guān)的設(shè)置和調(diào)整都與水平串聯(lián)非常相似。請檢查以下示例。
mat1t = t(mat1)
mat2t = t(mat2)
ht1 = Heatmap(mat1t, name = "rnorm", col = col_rnorm, row_title = "rnorm")
ht2 = Heatmap(mat2t, name = "runif", col = col_runif, row_title = "runif")
ht3 = Heatmap(rbind(letters = le), name = "letters", col = col_letters)
ht_list = ht1 %v% ht2 %v% ht3
draw(ht_list)

draw(ht_list, column_km = 2)

ha = HeatmapAnnotation(foo = anno_barplot(1:12, height = unit(2, "cm")))
ht_list = ht1 %v% ha %v% ht2 %v% ht3
draw(ht_list, column_km = 2)

ht1 = Heatmap(mat1t, name = "rnorm", col = col_rnorm, row_km = 2)
ht2 = Heatmap(mat2t, name = "runif", col = col_runif, row_km = 2)
ht3 = Heatmap(rbind(letters = le), name = "letters", col = col_letters)
ha = HeatmapAnnotation(foo = anno_barplot(1:12, height = unit(2, "cm")))
ht_list = ht1 %v% ha %v% ht2 %v% ht3
draw(ht_list, column_km = 2)

對于垂直熱圖列表,現(xiàn)在行注釋(right_annotation和left_annotation)應該是熱圖組件,它們的調(diào)整就像水平熱圖列表的列注釋一樣。
ht1 = Heatmap(mat1t, name = "rnorm", col = col_rnorm, row_km = 2,
left_annotation = rowAnnotation(foo1 = 1:10, bar1 = anno_barplot(1:10)))
ha = HeatmapAnnotation(foo = anno_barplot(1:12, height = unit(2, "cm"),
axis_param = list(side = "right")))
ht2 = Heatmap(mat2t, name = "runif", col = col_runif, row_km = 2,
left_annotation = rowAnnotation(foo2 = 1:10))
ht3 = Heatmap(rbind(letters = le), name = "letters", col = col_letters)
ht_list = ht1 %v% ha %v% ht2 %v% ht3
draw(ht_list, column_km = 2)

由于rowAnnotation()允許任意數(shù)量的注釋,上面顯示的方式是同時水平和垂直擴展熱圖列表的唯一方法。
4.10 熱圖列表的子集
類似于Heatmap子集對象,熱圖列表也可以通過提供行索引和列索引來子集化。對于水平熱圖列表,行索引對應所有熱圖和注釋中的行,而列索引僅對應熱圖和注釋的一個子集。對于垂直熱圖列表,情況正好相反。
下面我們以水平熱圖列表為例。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm,
left_annotation = rowAnnotation(foo1 = 1:12, bar1 = anno_points(1:12)))
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ha = rowAnnotation(foo2 = anno_barplot(1:12), bar2 = 12:1)
ht_list = ht1 + ht2 + ha
names(ht_list)
## [1] "rnorm" "runif" "foo2" "bar2"
ht_list[1:6, c("rnorm", "bar2")]

foo1和bar是rnorm熱圖的組成部分,因此不能在子集函數(shù)中選擇它們,而foo2和bar2是獨立的行注釋,可以選擇它們的子集。
4.11 繪制熱圖列表
在交互式R會話中直接進入HeatmapList對象show()調(diào)用draw()內(nèi)部調(diào)用該方法的方法。當你進入對象后沒有繪圖時,你應該明確使用draw():
# code only for demonstration
draw(ht_list, ...)
4.12 獲取順序和樹狀圖
row_order(), column_order(),row_dend()和column_dend()可用于從熱圖列表中檢索相應的信息。需要將這些函數(shù)應用于draw()。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm)
ht2 = Heatmap(mat2, name = "runif", col = col_runif)
ht_list = ht1 + ht2
ht_list = draw(ht_list)
row_order(ht_list)
## [1] 10 4 8 2 1 12 11 6 7 3 9 5
column_order(ht_list)
## $rnorm
## [1] 5 2 7 6 10 1 9 8 4 3
##
## $runif
## [1] 4 10 2 5 7 6 1 3 8 9
如果行或列被拆分,返回的值也將是一個列表。
ht1 = Heatmap(mat1, name = "rnorm", col = col_rnorm)
ht2 = Heatmap(mat2, name = "runif", col = col_runif, column_km = 2)
ht_list = ht1 + ht2
ht_list = draw(ht_list, row_km = 2)
row_order(ht_list)
## $`1`
## [1] 7 3 9 5
##
## $`2`
## [1] 10 4 8 2 1 12 11 6
column_order(ht_list)
## $rnorm
## $rnorm[[1]]
## [1] 5 2 7 6 10 1 9 8 4 3
##
##
## $runif
## $runif$`2`
## [1] 4 10 2 5
##
## $runif$`1`
## [1] 7 6 1 3 8 9
您可以為列順序指定某個熱圖。
column_order(ht_list, name = "runif")
## $`2`
## [1] 4 10 2 5
##
## $`1`
## [1] 7 6 1 3 8 9
提取樹狀圖的邏輯相同,垂直熱圖列表的邏輯也相同,可以參照水平熱圖列表。
4.13 全局參數(shù)修改
ht_opt()是一個全局控制參數(shù)的一些選項函數(shù)。您可以通過此全局函數(shù)同時為所有熱圖/注釋設(shè)置一些參數(shù)。請注意,您應該將其放在熱圖代碼之前,并在繪制熱圖后重置所有選項值,避免影響下一個熱圖。
ht_opt
## Option Value
## -------------------------:----------
## heatmap_row_names_gp NULL
## heatmap_column_names_gp NULL
## heatmap_row_title_gp NULL
## heatmap_column_title_gp NULL
## legend_title_gp NULL
## legend_title_position NULL
## legend_labels_gp NULL
## legend_grid_height NULL
## legend_grid_width NULL
## legend_border NULL
## legend_gap 4mm, 4mm
## heatmap_border NULL
## annotation_border NULL
## fast_hclust FALSE
## show_parent_dend_line TRUE
## verbose FALSE
## message TRUE
## show_vp FALSE
## simple_anno_size 5mm
## DENDROGRAM_PADDING 0.5mm
## DIMNAME_PADDING 1mm
## TITLE_PADDING NULL
## COLUMN_ANNO_PADDING 1mm
## ROW_ANNO_PADDING 1mm
## HEATMAP_LEGEND_PADDING 2mm
## ANNOTATION_LEGEND_PADDING 2mm
## save_last FALSE
## validate_names TRUE
有以下參數(shù)來控制所有熱圖:
-
heatmap_row_names_gp:row_names_gp全部設(shè)置Heatmap()。 -
heatmap_column_names_gp:column_names_gp全部設(shè)置Heatmap()。 -
heatmap_row_title_gp:row_title_gp全部設(shè)置Heatmap()。 -
heatmap_column_title_gp:column_title_gp全部設(shè)置Heatmap()。 -
heatmap_border:border全部設(shè)置Heatmap()。
以下參數(shù)控制圖例:
-
legend_title_gp:title_gp在所有熱圖圖例和注釋圖例中設(shè)置。 -
legend_title_position:title_position在所有熱圖圖例和注釋圖例中設(shè)置。 -
legend_labels_gp:labels_gp在所有熱圖圖例和注釋圖例中設(shè)置。 -
legend_grid_width:grid_width在所有熱圖圖例和注釋圖例中設(shè)置。 -
legend_grid_height:grid_height在所有熱圖圖例和注釋圖例中設(shè)置。 -
legend_border:border在所有熱圖圖例和注釋圖例中設(shè)置。
以下參數(shù)控制熱圖注釋:
-
annotation_border:border全部設(shè)置HeatmapAnnotation()。 -
anno_simple_size: 設(shè)置簡單注釋的大小。
以下參數(shù)控制熱圖組件之間的空間:
-
DENDROGRAM_PADDING:樹狀圖和熱圖主體之間的空間。 -
DIMNAME_PADDING:行/列名稱和熱圖主體之間的空格。 -
TITLE_PADDING:行/列標題和熱圖正文之間的空間。 -
COLUMN_ANNO_PADDING:列注釋和熱圖主體之間的空間。 -
ROW_ANNO_PADDING:行注釋和熱圖主體之間的空間。
其他參數(shù):
-
fast_hclust: 是否用于fastcluster::hclust()加速聚類? -
show_parent_dend_line: 分割熱圖時,是否添加虛線來標記父樹狀圖和子樹狀圖?
您可以通過傳統(tǒng)方式(如base::options())或$運算符獲取或設(shè)置選項值 :
ht_opt("heatmap_row_names_gp")
ht_opt$heatmap_row_names_gp
# to set option values
ht_opt("heatmap_row_names_gp" = gpar(fontsize = 8))
ht_opt$heatmap_row_names_gp = gpar(fontsize = 8)
通過以下方式重置為默認值:
ht_opt(RESET = TRUE)
下面的例子展示了全局控制一些圖形參數(shù)。
ht_opt(heatmap_column_names_gp = gpar(fontface = "italic"),
heatmap_column_title_gp = gpar(fontsize = 10),
legend_border = "black",
heatmap_border = TRUE,
annotation_border = TRUE
)
ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1",
top_annotation = HeatmapAnnotation(foo = 1:10))
ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2",
top_annotation = HeatmapAnnotation(bar = 1:10))
ht1 + ht2

ht_opt(RESET = TRUE)
這些全局參數(shù)也可以在draw()函數(shù)中設(shè)置可以臨時改變?nèi)謪?shù),繪制完成后重新設(shè)置回來。請查看draw,HeatmapList-method的幫助頁面。
4.14 調(diào)整注釋產(chǎn)生的空白
熱圖注釋可能有注釋名稱和軸,在最終布局中排列熱圖組件時也會考慮這些空間。有時,這種調(diào)整結(jié)果并不美觀,您可能會在圖中看到不必要的空白區(qū)域。
一種情況是對于沒有行名稱的矩陣,熱圖右側(cè)的空間由注釋名稱的大小決定,這會導致熱圖和圖例之間出現(xiàn)空白。此外,熱圖列表級別的行標題繪制在注釋軸的左側(cè),如果沒有行樹狀圖,則會提供空白區(qū)域。
adjust_annotation_extension控制是否考慮布局的注釋名稱和軸的空間。比較以下兩個圖。
m = matrix(rnorm(100), 10)
ht = Heatmap(m, name = "mat",
top_annotation = HeatmapAnnotation(foo = anno_points(1:10)),
show_row_dend = FALSE)
draw(ht, row_title = "fooooooooooo", adjust_annotation_extension = TRUE, # default
column_title = "adjust_annotation_extension = TRUE")
draw(ht, row_title = "fooooooooooo", adjust_annotation_extension = FALSE,
column_title = "adjust_annotation_extension = FALSE")

另一種部分解決空間問題的方法是將注釋名稱向左移動并使用 heamtap 級別的行標題。
Heatmap(m, name = "mat",
top_annotation = HeatmapAnnotation(foo = anno_points(1:10),
annotation_name_side = "left"),
row_title = "fooooooooooo",
show_row_dend = FALSE)

但是,有時也需要對注釋進行這種調(diào)整,例如當熱圖非常短時:
ht = Heatmap(m, name = "mat",
top_annotation = HeatmapAnnotation(foo = anno_points(1:10)),
show_row_dend = FALSE)
draw(ht, row_title = "fooooooooooo", adjust_annotation_extension = TRUE,
column_title = "adjust_annotation_extension = TRUE")

因此,我們將其adjust_annotation_extension設(shè)置TRUE為默認值,用戶可以根據(jù)具體場景進行配置。
4.15 手動圖形周圍空間
ComplexHeatmap的布局并不完美,仍有可能將某些文本繪制到繪圖區(qū)域之外。在這種情況下,您可以在draw()函數(shù)中手動設(shè)置參數(shù)padding以增加最終繪圖周圍的空白區(qū)域。
padding的值應該是4個長度的單位向量。這四個值分別對應底部、左側(cè)、頂部和右側(cè)的空間。
下面的例子不是一個完美的例子,因為行名的最大寬度可以通過max_row_name_width參數(shù)控制,但我們?nèi)匀豢梢杂盟鼇硌菔?code>padding.
m2 = m
rownames(m2) = paste0("R", 1:10)
rownames(m2)[1] = "a long long long long long row name"
ht = Heatmap(m2, name = "mat", row_names_side = "left", show_row_dend = FALSE)
draw(ht, padding = unit(c(2, 20, 2, 2), "mm")) ## see right heatmap in following
