r - 从 pheatmap 中的 cutree_rows 组中提取基因/观察值
问题描述
您如何从cutree_rows = 3
in生成的行组中提取基因/观察值pheatmap
?会是obj$tree_row$...
?
obj <- pheatmap(mat, annotation_col = anno, fontsize_row = 10, show_colnames = F, show_rownames = F, cutree_cols = 3, cluster_cols = FALSE, color = col, scale = 'row',cutree_rows = 3)
obj$kmeans$cluster
我已经看到,如果您通过运行这样的方式应用 k 均值,您可以找到基因列表,有没有办法在热图中保留聚类但减少观察次数?
解决方案
您可以再次对其进行cutree,例如数据是这样的:
set.seed(2020)
mat = matrix(rnorm(200),20,10)
rownames(mat) = paste0("g",1:20)
obj = pheatmap(mat,cluster_cols = FALSE, scale = 'row',cutree_rows = 3)
做可爱:
cl = cutree(obj$tree_row,3)
ann = data.frame(cl)
rownames(ann) = rownames(mat)
ann
cl
g1 1
g2 2
g3 1
g4 2
g5 3
g6 1
g7 2
g8 1
g9 1
g10 2
g11 3
g12 2
g13 2
g14 1
g15 2
g16 2
g17 1
g18 3
g19 3
g20 2
我们再次绘制它以查看它是否正确,
pheatmap(mat,cluster_cols = FALSE, scale = 'row',cutree_rows = 3,annotation_row=ann)
推荐阅读
- python - 将包含字典的字符串转换为字典列表
- android - SharedPreferences 用于显示文本,不显示
- javascript - 通过 url 请求仅获取存储在服务器中的 JSON 数据库的特定元素
- php - 如何在嵌套调用 eval() 时使用单引号?
- reactjs - 使用 require() 从相对路径加载图像时找不到模块
- google-sheets - 如何在不写任何公式的情况下设置单元格值
- powershell - 从对象格式化 CSV
- javascript - Fullcalendar 错误时刻 properties.push 不是函数
- android - Android 字体资源与字体资源 (API 26)
- ios - 如何通过应用内购买锁定 tableview 中的特定行?