zes*_*sla 1 r heatmap pheatmap
我使用下面的代码制作了热图:
library(pheatmap)
library(dplyr)
data = data.frame(matrix(runif(10*10), ncol=10))
data$sample = rep(c("tumour", "normal"), 5)
data$subject.ID = paste('Subject', 1:10)
data = data %>% arrange(sample)
# for row annotation
my_sample_col = data %>% select(sample)
rownames(my_sample_col) = data$subject.ID
# data matrix
mat = as.matrix(data %>% select(-sample, -subject.ID))
rownames(mat) = data$subject.ID
pheatmap(mat,
scale='row',
annotation_row = my_sample_col,
annotation_names_row=F,
cluster_rows = FALSE,
cluster_cols = FALSE,
show_colnames = FALSE,
show_rownames = FALSE)
Run Code Online (Sandbox Code Playgroud)
我想在第 5 行和第 6 行之间放置一个间隙,以根据我的行注释分隔热图。
从pheatmap功能上看,这个论证gaps_row似乎起到了作用。
vector of row indices that show shere to put gaps into heatmap. Used only if the rows are not clustered.
Run Code Online (Sandbox Code Playgroud)
我不知道如何实施。有人可以帮我弄这个吗?多谢。
我建议使用ComplexHeatmap包(网站;Gu et al, 2016)。您可以使用 来安装它devtools::install_github("jokergoo/ComplexHeatmap")。
它具有更多功能,但您也必须投入更多时间(例如,行注释和矩阵缩放)。
library(ComplexHeatmap)
# Create annotation for rows
my_sample_col_ano <- rowAnnotation(sample = my_sample_col$sample,
show_annotation_name = FALSE)
# Scale original matrix row-wise
matS <- t(apply(mat, 1, scale))
# Plot heatmap
Heatmap(matS,
# Remove name from fill legend
name = "",
# Keep original row/col order
row_order = rownames(matS), column_order = colnames(matS),
# Add left annotation (legend with tumor/normal)
left_annotation = my_sample_col_ano,
# ACTUAL SPLIT by sample group
row_split = my_sample_col$sample,
show_row_names = FALSE, show_column_names = FALSE,
show_row_dend = FALSE, show_column_dend = FALSE,
row_title = NULL)
Run Code Online (Sandbox Code Playgroud)
如果您想使用等于您的组大小的原始pheatmap传递参数(即正常):gaps_row
pheatmap(mat,
scale='row',
gaps_row = 5,
annotation_row = my_sample_col,
annotation_names_row=F,
cluster_rows = FALSE,
cluster_cols = FALSE,
show_colnames = FALSE,
show_rownames = FALSE)
Run Code Online (Sandbox Code Playgroud)
如果您可以多于两个组而不是将数值硬编码为gaps_row(即gaps_row = 5),则可以传递此片段(head(as.numeric(cumsum(table(my_sample_col$sample))), -1))。
| 归档时间: |
|
| 查看次数: |
14909 次 |
| 最近记录: |