{"id":683,"date":"2024-06-25T22:43:21","date_gmt":"2024-06-25T14:43:21","guid":{"rendered":"https:\/\/linguopeng.top\/?p=683"},"modified":"2024-06-25T23:00:31","modified_gmt":"2024-06-25T15:00:31","slug":"%e8%b7%9f%e7%9d%80imeta%e5%ad%a6%e5%81%9a%e5%9b%be%ef%bd%9ccomplexheatmap%e7%bb%98%e5%88%b6%e5%a4%9a%e6%a0%b7%e7%9a%84%e7%83%ad%e5%9b%be","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=683","title":{"rendered":"\u8ddf\u7740iMeta\u5b66\u505a\u56fe\uff5cComplexHeatmap\u7ed8\u5236\u591a\u6837\u7684\u70ed\u56fe"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code># \u987e\u7956\u5149(Zuguang Gu)\n# 2022-09-20\n# \u5982\u679c\u4f60\u4f7f\u7528\u672c\u4ee3\u7801\uff0c\u8bf7\u5f15\u7528\uff1a Zuguang Gu. 2022. Complex heatmap visualization. iMeta 1: e43. https:\/\/doi.org\/10.1002\/imt2.43\n# \n# \u7ffb\u8bd1\u53ca\u6ce8\u91ca\uff1a\u519c\u5fc3\u751f\u4fe1\u5de5\u4f5c\u5ba4\n# \n# \u70ed\u56fe\uff08Heatmap\uff09\u662f\u77e9\u9635\u7c7b\u578b\u6570\u636e\u6700\u4e3a\u5e38\u7528\u7684\u53ef\u89c6\u5316\u65b9\u6cd5\uff0c\u5728\u751f\u7269\u5b66\u9886\u57df\u5e38\u7528\u4e8e\u5404\u79cd\u7ec4\u5b66\u6570\u636e\u7684\u53ef\u89c6\u5316\uff0c\u4f8b\u5982\u57fa\u56e0\u8868\u8fbe\u91cf\u6570\u636e\u3001\u7269\u79cd\u4e30\u5ea6\u5206\u5e03\u3001\u8868\u89c2\u9057\u4f20\u4fe1\u53f7\u6570\u636e\u7b49\u3002\u73b0\u5982\u4eca\u591a\u7ec4\u5b66\u6570\u636e\u4e0d\u65ad\u6d8c\u73b0\uff0c \u73b0\u6709\u7684R\u8bed\u8a00\u5305\u4f8b\u5982 gplots\u3001pheatmap\u3001ggplot2_\u7ed8\u5236\u70ed\u56fe\u7684\u529f\u80fd\u8f83\u4e3a\u5355\u4e00\uff0c\u5df2\u65e0\u6cd5\u6ee1\u8db3\u5927\u5bb6\u4ece\u591a\u4e2a\u7ef4\u5ea6\u3001\u5bf9\u591a\u7c7b\u578b\u6570\u636e\u66f4\u52a0\u5145\u5206\u53ef\u89c6\u5316\u7684\u9700\u6c42\u3002ComplexHeatmap_ \u7531\u5fb7\u56fd\u56fd\u5bb6\u80bf\u7624\u75be\u75c5\u4e2d\u5fc3\u987e\u987e\u7956\u5149\u535a\u58eb\u5f00\u53d1\uff0c\u8be5R\u5305\u6b63\u5982\u5176\u540d\u4e00\u6837\u590d\u6742\uff0c\u4f46\u662f\u5176\u7ed8\u5236\u70ed\u56fe\u529f\u80fd\u5374\u582a\u79f0\u5168\u9762\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u4ee5\u987e\u7956\u5149\u535a\u58eb\u53d1\u8868\u5728iMeta\u4e0a\u7684\u65b9\u6cd5\u8bba\u6587Complex heatmap visualization\n# \n# iMeta | \u5fb7\u56fd\u56fd\u5bb6\u80bf\u7624\u4e2d\u5fc3\u987e\u7956\u5149\u53d1\u8868\u590d\u6742\u70ed\u56fe(ComplexHeatmap)\u53ef\u89c6\u5316\u65b9\u6cd5\n# \u672c\u6587\u5bf9\u5176\u4e2d\u7684Figure 2\u56feA\u4e3a\u4f8b\uff0c\u5bf9_ComplexHeatmap_\u7684\u70ed\u56fe\u7ed8\u5236\u65b9\u6cd5\u8fdb\u884c\u8bb2\u89e3\u548c\u63a2\u8ba8\uff0c\u5148\u4e0a\u539f\u56fe\uff1a\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/1-1.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"925\" height=\"968\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/1-1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-686\"\/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># R\u5305\u68c0\u6d4b\u548c\u5b89\u88c5\n# 1.\u5148\u5b89\u88c5\u6240_ComplexHeatmap_\u5305\u53ca\u5176\u4f9d\u8d56\u5e76\u5c06\u6240\u6709\u5305\u8f7d\u5165\n# \u68c0\u67e5\u5f00\u53d1\u8005\u5de5\u5177devtools\uff0c\u5982\u6ca1\u6709\u5219\u5b89\u88c5\nif (!require(\"devtools\"))\n  install.packages(\"devtools\")\n# \u52a0\u8f7d\u5f00\u53d1\u8005\u5de5\u5177devtools\nlibrary(devtools)\n# \u68c0\u67e5\u70ed\u56fe\u5305\uff0c\u6ca1\u6709\u5219\u901a\u8fc7github\u5b89\u88c5\u6700\u65b0\u7248\nif (!require(\"ComplexHeatmap\"))\n  install_github(\"jokergoo\/ComplexHeatmap\")\n# ComplexHeatmap\u4f9d\u8d56\u5173\u7cfb\nif (!require(\"circlize\"))\n  install_github(\"jokergoo\/circlize\")\n# \u7528\u4e8e\u7ed8\u5236\u77e9\u9635\u5217\u65b9\u5411\u4e0a\u7684\u5c42\u6b21\u805a\u7c7b\u7ed3\u679c\nif (!require(\"dendextend\"))\n  install.packages('dendextend') \n# \u52a0\u8f7d\u5305\nlibrary(ComplexHeatmap)\nlibrary(circlize)\nlibrary(dendextend)\n# \u751f\u6210\u6d4b\u8bd5\u6570\u636e\n# 2.\u8bbe\u7f6e\u968f\u673a\u79cd\u5b50\u5e76\u751f\u621018 * 24\u7684\u968f\u673a\u6570\u636emat\n# \u8bbe\u7f6e\u968f\u673a\u6570\u79cd\u5b50\uff0c\u786e\u4fdd\u6570\u636e\u53ef\u91cd\u590d\nset.seed(123)\n# \u5206\u5c0f\u7ec4\uff0c\u7528\u4e8e\u5f62\u6210\u4e0d\u540c\u805a\u7c7b\u7c07\nnr1 = 4; nr2 = 8; nr3 = 6; nr = nr1 + nr2 + nr3\nnc1 = 6; nc2 = 8; nc3 = 10; nc = nc1 + nc2 + nc3\nmat = cbind(rbind(matrix(rnorm(nr1*nc1, mean = 1,   sd = 0.5), nr = nr1),\n                  matrix(rnorm(nr2*nc1, mean = 0,   sd = 0.5), nr = nr2),\n                  matrix(rnorm(nr3*nc1, mean = 0,   sd = 0.5), nr = nr3)),\n            rbind(matrix(rnorm(nr1*nc2, mean = 0,   sd = 0.5), nr = nr1),\n                  matrix(rnorm(nr2*nc2, mean = 1,   sd = 0.5), nr = nr2),\n                  matrix(rnorm(nr3*nc2, mean = 0,   sd = 0.5), nr = nr3)),\n            rbind(matrix(rnorm(nr1*nc3, mean = 0.5, sd = 0.5), nr = nr1),\n                  matrix(rnorm(nr2*nc3, mean = 0.5, sd = 0.5), nr = nr2),\n                  matrix(rnorm(nr3*nc3, mean = 1,   sd = 0.5), nr = nr3))\n)\ndim(mat) #\u67e5\u770b\u6570\u636e\u7ef4\u5ea6\n#&gt; &#91;1] 18 24\n\n# \u53ef\u9009\u4ece\u6587\u4ef6\u8bfb\u53d6\u77e9\u9635\n# write.table(mat, file=\"mat.txt\", sep=\"\\t\", quote=F, row.names=T, col.names=T)\n# mat = as.matrix(read.table((\"mat.txt\"), header=T, row.names=1, sep=\"\\t\", comment.char=\"\"))\n\nmat = mat&#91;sample(nr, nr), sample(nc, nc)] # \u6253\u4e71\u6570\u636e\nrownames(mat) = paste0(\"row\", seq_len(nr)) # \u884c\u547d\u540d\ncolnames(mat) = paste0(\"column\", seq_len(nc)) # \u5217\u547d\u540d\n# \u70ed\u56fe\u9884\u89c8\n# 3.\u5f00\u59cb\u7528ComplexHeatmap\u4e2d\u6700\u91cd\u8981\u7684\u51fd\u6570Heatmap()\u7ed8\u5236\u4e00\u5f20\u7b80\u5355\u7684\u70ed\u56fe\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u9ed8\u8ba4\u53c2\u6570\u4e0b\uff0c\n# ComplexHeatmap\u4f1a\u751f\u6210\u56fe\u4f8b\u3001\u884c\u5217\u540d\u5e76\u5bf9\u884c\u5217\u5206\u522b\u805a\u7c7b\uff0c\u805a\u7c7b\u65b9\u6cd5\u548c\u521a\u624d\u6211\u4eec\u7528dendextend\u505a\u805a\u7c7b\u65f6\u7684\u2019complete\u2019\u5c42\u6b21\u805a\u7c7b\u65b9\u6cd5\u76f8\u540c\nHeatmap(mat)\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/2-1.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1500\" height=\"900\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/2-1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-687\"\/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># \u70ed\u56fe\u805a\u7c7b\u7740\u8272\n# 4.\u5bf9\u5217\u6570\u636e\u505a\u5c42\u6b21\u805a\u7c7b\uff0chclust()\u51fd\u6570\u505a\u805a\u7c7b\u65f6\u9ed8\u8ba4\u65b9\u6cd5\u4e3a\u2019complete\u2019\u5373\u4f7f\u7528\u6837\u672c\u6700\u5927\u8ddd\u79bb\u5b9a\u4e49\u4e24\u4e2a\u7c7b\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u91c7\u7528\u6b27\u5f0f\u8ddd\u79bb\u4f5c\u4e3a\u8ddd\u79bb\u7684\u5ea6\u91cf\uff0ccolor_branches()\u7528\u4e8e\u7ed9\u4e0d\u540c\u5206\u652f\u7740\u8272\n# \u5c42\u6b21\u805a\u7c7b\ncolumn_dend = as.dendrogram(hclust(dist(t(mat))))\n# \u5206\u652f\u7740\u8272\ncolumn_dend = color_branches(column_dend, k = 3)\n# 5.\u5c1d\u8bd5\u4e00\u4e9b\u53c2\u6570\u7684\u8bbe\u7f6e\uff0c\u7531\u4e8eComplexHeatmap\u57fa\u4e8egrid\u7ed8\u56fe\u6846\u67b6\uff0c\n# \u6240\u4ee5\u51e1\u662f\u91cf\u5316\u957f\u5ea6\u7684\u53c2\u6570\u90fd\u9700\u8981\u7528unit()\u51fd\u6570\u5236\u5b9a\uff0c\n# \u4f8b\u5982\u4e0b\u9762\u7684row_dend_width\u3002cluster_columns\u548ccluster_rows\u53c2\u6570\n# \u53ef\u4ee5\u6307\u5b9a\u805a\u7c7b\u65b9\u6cd5\u4e3a\u6211\u4eec\u524d\u9762\u8bbe\u7f6e\u597d\u7684dendrogram\u5bf9\u8c61\nHeatmap(mat, name = \"mat\", \n        row_dend_width = unit(2, \"cm\"), # \u884c\u805a\u7c7b\u6811\u7684\u5bbd\u5ea6\n        cluster_columns = column_dend, # \u5217\u805a\u7c7b\u65b9\u6cd5\u6307\u5b9a\u4e3a\u524d\u9762\u8bbe\u7f6e\u7684dendrogram\u5bf9\u8c61\n        column_title = \"(A) A heatmap with various annotations\", # \u6807\u9898\n        show_column_names = FALSE, # \u4e0d\u663e\u793a\u5217\u540d\n        row_split = rep(c(\"A\", \"B\"), 9), # \u884c\u5206\u5272\u540e\u7684\u547d\u540d\n        row_km = 2, # \u884ck-means\u805a\u7c7b\u7684\u7c7b\u522b\u6570\n        column_split = 3  # \u5217\u5206\u5272\u6570\n)\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/3.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1500\" height=\"900\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/3.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-688\" style=\"width:840px;height:auto\"\/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662frow_km\u53c2\u6570\uff0c\u5b98\u65b9\u7684\u89e3\u91ca\u5982\u4e0b\uff1a &gt; Apply k-means clustering on rows. \n# If the value is larger than 1, the heatmap will be split by rows according to the k-means clustering. \n# For each row slice, hierarchical clustering is still applied with parameters above.\n# \u8fd9\u5c31\u662f\u8bf4\u8fd9\u4e2a\u53c2\u6570\u4e00\u65e6\u6307\u5b9a\u4e00\u4e2a\u5927\u4e8e1\u7684\u6570\uff0c\u5c31\u4f1a\u5148\u8fdb\u884c\u4e00\u4e2ak-means\u805a\u7c7b\uff0c\n# \u7136\u540e\u5728k\u4e2a\u7c7b\u522b\u5185\u7528\u9ed8\u8ba4\u7684\u5c42\u6b21\u805a\u7c7b\u65b9\u6cd5\u8fdb\u884c\u7b2c\u4e8c\u6b21\u805a\u7c7b\uff0c\u540c\u65f6\uff0c\u70ed\u56fe\u7684\u884c\u4e5f\u4f1a\u6839\u636e\u805a\u7c7b\u7ed3\u679c\u5207\u5272\u5f00\u6765\n# \u70ed\u56fe\u6ce8\u91ca\n# 6.\u6700\u540e\uff0c\u518d\u628a\u884c\u548c\u5217\u7684annotation\u52a0\u4e0a\uff0canno_points()\u7528\u4e8e\u5728\u77e9\u9635\u4e0a\u65b9\u7ed8\u5236\u70b9\u56fe\uff0c\u6570\u503c\u4e3a0-1\u4e4b\u95f4\u7684\u968f\u673a\u6570\uff1b\n# anno_barplot()\u7528\u4e8e\u5728\u77e9\u9635\u53f3\u8fb9\u7ed8\u5236\u5806\u53e0\u67f1\u72b6\u56fe\uff0c\u56fe\u4e2d\u989c\u8272\u5c5e\u6027\u7528grid\u6846\u67b6\u4e2d\u7684gpar()\u51fd\u6570\u63a7\u5236\\\n(ht = Heatmap(mat, name = \"mat\", \n              row_dend_width = unit(2, \"cm\"), # \u884c\u805a\u7c7b\u6811\u7684\u5bbd\u5ea6\n              cluster_columns = column_dend, # \u5217\u805a\u7c7b\u65b9\u6cd5\u6307\u5b9a\u4e3a\u524d\u9762\u8bbe\u7f6e\u7684dendrogram\u5bf9\u8c61\n              column_title = \"(A) A heatmap with various annotations\", # \u6807\u9898\n              show_column_names = FALSE, # \u4e0d\u663e\u793a\u5217\u540d\n              row_split = rep(c(\"A\", \"B\"), 9), # \u884c\u5206\u5272\u540e\u7684\u547d\u540d\n              row_km = 2, # \u884ck-means\u805a\u7c7b\u7684\u7c7b\u522b\u6570\n              column_split = 3,  # \u5217\u5206\u5272\u6570\n              top_annotation = HeatmapAnnotation(foo1 = 1:24, \n                                                 bar1 = anno_points(runif(24))),\n              right_annotation = rowAnnotation(foo2 = 18:1,\n                                               bar2 = anno_barplot(cbind(runif(18), \n                                                                         runif(18)),\n                                                                   gp = gpar(fill = 2:3), \n                                                                   width = unit(2, \"cm\")))\n))\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/4.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1500\" height=\"900\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/4.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-689\"\/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4fdd\u5b58\u56fe\u4e3aPDF\uff0c\u6307\u5b9a\u5bbd\u548c\u9ad8\npdf(\"Figure2A.pdf\", width = 8, height = 4.5)\nprint(ht)\ndev.off()\n#&gt; png \n#&gt;   2<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/5.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1094\" height=\"1312\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/5.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-690\" style=\"width:840px;height:auto\"\/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u9644.\u5b8c\u6574\u4ee3\u7801\nlibrary(ComplexHeatmap)\nlibrary(circlize)\nlibrary(dendextend)\n\nset.seed(123)\nnr1 = 4; nr2 = 8; nr3 = 6; nr = nr1 + nr2 + nr3\nnc1 = 6; nc2 = 8; nc3 = 10; nc = nc1 + nc2 + nc3\nmat = cbind(rbind(matrix(rnorm(nr1*nc1, mean = 1,   sd = 0.5), nr = nr1),\n                  matrix(rnorm(nr2*nc1, mean = 0,   sd = 0.5), nr = nr2),\n                  matrix(rnorm(nr3*nc1, mean = 0,   sd = 0.5), nr = nr3)),\n            rbind(matrix(rnorm(nr1*nc2, mean = 0,   sd = 0.5), nr = nr1),\n                  matrix(rnorm(nr2*nc2, mean = 1,   sd = 0.5), nr = nr2),\n                  matrix(rnorm(nr3*nc2, mean = 0,   sd = 0.5), nr = nr3)),\n            rbind(matrix(rnorm(nr1*nc3, mean = 0.5, sd = 0.5), nr = nr1),\n                  matrix(rnorm(nr2*nc3, mean = 0.5, sd = 0.5), nr = nr2),\n                  matrix(rnorm(nr3*nc3, mean = 1,   sd = 0.5), nr = nr3))\n)\n\nmat = mat&#91;sample(nr, nr), sample(nc, nc)] # random shuffle rows and columns\nrownames(mat) = paste0(\"row\", seq_len(nr))\ncolnames(mat) = paste0(\"column\", seq_len(nc))\n\ncolumn_dend = as.dendrogram(hclust(dist(t(mat))))\ncolumn_dend = color_branches(column_dend, k = 3) # `color_branches()` returns a dendrogram object\n\nHeatmap(mat, name = \"mat\", \n        row_dend_width = unit(2, \"cm\"), # \u884c\u805a\u7c7b\u6811\u7684\u5bbd\u5ea6\n        cluster_columns = column_dend, # \u5217\u805a\u7c7b\u65b9\u6cd5\u6307\u5b9a\u4e3a\u524d\u9762\u8bbe\u7f6e\u7684dendrogram\u5bf9\u8c61\n        column_title = \"(A) A heatmap with various annotations\", # \u6807\u9898\n        show_column_names = FALSE, # \u4e0d\u663e\u793a\u5217\u540d\n        row_split = rep(c(\"A\", \"B\"), 9), # \u884c\u5206\u5272\u540e\u7684\u547d\u540d\n        row_km = 2, # \u884ck-means\u805a\u7c7b\u7684\u7c7b\u522b\u6570\n        column_split = 3,  # \u5217\u5206\u5272\u6570\n        top_annotation = HeatmapAnnotation(foo1 = 1:24, \n                                           bar1 = anno_points(runif(24))),\n        right_annotation = rowAnnotation(foo2 = 18:1,\n                                         bar2 = anno_barplot(cbind(runif(18), \n                                                                   runif(18)),\n                                                        gp = gpar(fill = 2:3), \n                                                        width = unit(2, \"cm\")))\n        )\n#\u4ee5\u4e0a\u4ee3\u7801\u6765\u81eaZuguang Gu\u535a\u58eb\u7684githubhttps:\/\/github.com\/jokergoo\/ComplexHeatmap_v2_paper_code\uff0c#\u8bba\u6587\u4e2d\u5176\u4ed6\u7684\u56fe\u90fd\u6709\u76f8\u5e94\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u5927\u5bb6\u53ef\u4ee5\u53c2\u8003\u5b66\u4e60\uff0c\u7ed8\u5236\u51fa\u66f4\u52a0\u6f02\u4eae\u7684\u70ed\u56fe\uff01<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/6.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1500\" height=\"900\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/6.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-691\"\/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-683","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=683"}],"version-history":[{"count":3,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions"}],"predecessor-version":[{"id":693,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions\/693"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}