{"id":23532,"date":"2024-01-05T17:03:47","date_gmt":"2024-01-05T09:03:47","guid":{"rendered":"http:\/\/www.biocloudservice.com\/wordpress\/?p=23532"},"modified":"2024-01-05T17:03:47","modified_gmt":"2024-01-05T09:03:47","slug":"5%e5%88%86%e9%92%9f%e5%ad%a6%e4%bc%9a%e7%bb%98%e5%88%b6%e7%83%ad%e5%9b%bepheatmap","status":"publish","type":"post","link":"http:\/\/www.biocloudservice.com\/wordpress\/?p=23532","title":{"rendered":"5\u5206\u949f\u5b66\u4f1a\u7ed8\u5236\u70ed\u56fepheatmap"},"content":{"rendered":"<p>\u70ed\u56fe\u5728\u4e2a\u7ec4\u5b66\u4e2d\u7684\u5e94\u7528\u5341\u5206\u7684\u5e7f\u6cdb\uff0c\u5728\u6587\u732e\u4e2d\u7ecf\u5e38\u51fa\u73b0\uff0c\u5229\u7528\u989c\u8272\u76f4\u63a5\u5c55\u793a\u5728\u4e0d\u540c\u6837\u672c\u4e2d\u5c55\u793a\u57fa\u56e0\u3001\u4ee3\u8c22\u7269\u3001\u7269\u79cd\u7b49\u8868\u8fbe\u7684\u6c34\u5e73\u3002\u4e00\u5f20\u70ed\u56fe\u50cf\u4e94\u989c\u516d\u8272\u7684\u74f7\u7816\u4e00\u6837\u94fa\u5728\u6574\u5f20\u56fe\u4e2d\uff0c\u7ed9\u4eba\u89c6\u89c9\u4e0a\u7684\u7f8e\u611f\u3002\u901a\u8fc7R\u505aheatmap\u662f\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u90a3\u6211\u4eec\u4eca\u5929\u5c31\u6765\u5b66\u4e60\u4e00\u4e0b\u600e\u6837\u5feb\u901f\u7ed8\u5236\u70ed\u56fe\u5427\uff5e<\/p>\n<h2>\u5b89\u88c5\u5e76\u52a0\u8f7dpheatmap\u5305<\/h2>\n<p>#\u5b89\u88c5pheatmap\u5305<\/p>\n<p>install.packages(&#8220;pheatmap&#8221;)<\/p>\n<p>#\u52a0\u8f7d<\/p>\n<p>library(pheatmap)<\/p>\n<p>#\u8bbe\u7f6e\u5de5\u4f5c\u8def\u5f84<\/p>\n<p>setwd(&#8220;\/Users\/sansan\/Desktop\/\u672a\u547d\u540d\u6587\u4ef6\u5939\/&#8221;)<\/p>\n<h2>\u6784\u5efa\u6d4b\u8bd5\u6570\u636e\u96c6<\/h2>\n<p>#\u9996\u5148\u6784\u5efa\u4e00\u4e2a\u6570\u636e\u96c6\uff0c\u4f5c\u4e3a\u6211\u4eec\u5b66\u4e60\u7684\u793a\u4f8b<\/p>\n<p>test &lt;- matrix(rnorm(100),10,10)<\/p>\n<p>test[1:10,seq(1,10,2)] &lt;- test[1:10,seq(1,10,2)]+3<\/p>\n<p>test[5:10,seq(1,10,2)] &lt;- test[5:10,seq(1,10,2)]+3<\/p>\n<p>colnames(test) &lt;- paste(&#8220;Sample&#8221;,1:10,sep = &#8220;&#8221;)<\/p>\n<p>rownames(test) &lt;- paste(&#8220;Gene&#8221;,1:10,sep = &#8220;&#8221;)<\/p>\n<p>test<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"250\" class=\"wp-image-23533\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-08-13-34-30.png?resize=640%2C250\" alt=\"\u622a\u5c4f2023-06-08 13.34.30\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-08-13-34-30.png?w=706 706w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-08-13-34-30.png?resize=300%2C117 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-08-13-34-30.png?resize=600%2C235 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<h2>\u7ed8\u5236\u7b80\u5355\u7684\u70ed\u56fe<\/h2>\n<p>\u5f52\u4e00\u5316\u5904\u7406\u7684\u5fc5\u8981\u6027\uff1a\u662f\u4e00\u79cd\u6570\u636e\u9884\u5904\u7406\u4e2d\u7279\u5f81\u7f29\u653e\u7684\uff08feature scaling\uff09\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8ba9\u6240\u6709\u7684\u6570\u636e\u5904\u4e8e\u4e00\u79cd\u91cf\u7eb2\u7ea7\u522b\u8fdb\u884c\u5206\u6790\uff0c\u66f4\u5bb9\u6613\u76f4\u89c2\u7684\u9610\u660e\u6570\u636e\u7684\u5dee\u5f02\u6027\u3002\u4f8b\u5982\u5f52\u4e00\u5316\u5230\u30101\uff0c-1\u3011\u7684\u8303\u56f4\u5185\uff0c\u6d88\u9664\u4e86\u5f02\u5e38\u6837\u672c\u5bfc\u81f4\u7ed3\u679c\u4e0d\u826f\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u5728\u5e94\u7528\u524d\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3\u4e00\u4e9b\u5fc5\u8981\u7684\u53c2\u6570\u3002<\/p>\n<p>#scalec = &#8220;row&#8221; \u53c2\u6570\u8bbe\u5b9a\u5bf9\u884c\u8fdb\u884c\u5f52\u4e00\u5316\u5904\u7406<\/p>\n<p># clustering_method\u53c2\u6570\u8bbe\u5b9a\u4e0d\u540c\u805a\u7c7b\u65b9\u6cd5\uff0c\u9ed8\u8ba4\u4e3a&#8221;complete&#8221;,\u53ef\u4ee5\u8bbe\u5b9a\u4e3award, ward.D, ward.D2, single, complete, average, mcquitty, median or centroid<\/p>\n<p># clustering_distance_rows = &#8220;correlation&#8221;\u53c2\u6570\u8bbe\u5b9a\u884c\u805a\u7c7b\u8ddd\u79bb\u65b9\u6cd5\u4e3acorralation\uff0c\u9ed8\u8ba4\u4e3a\u6b27\u6c0f\u8ddd\u79bb&#8221;euclidean&#8221;<\/p>\n<p># legend_breaks\u53c2\u6570\u8bbe\u5b9a\u56fe\u4f8b\u663e\u793a\u8303\u56f4\uff0clegend_labels\u53c2\u6570\u6dfb\u52a0\u56fe\u4f8b\u6807\u7b7elegend_labels = c(&#8220;1.0&#8243;,&#8221;2.0&#8243;,&#8221;3.0&#8243;,&#8221;4.0&#8243;,&#8221;5.0&#8221;)<\/p>\n<p>#border=FALSE\u53c2\u6570\u53bb\u6389\u8fb9\u6846\u7ebf<\/p>\n<p>#border_color\u53c2\u6570\u8bbe\u5b9a\u6bcf\u4e2a\u70ed\u56fe\u683c\u5b50\u7684\u8fb9\u6846\u8272<\/p>\n<p>#show_rownames\u548cshow_colnames\u53c2\u6570\u8bbe\u5b9a\u662f\u5426\u663e\u793a\u884c\u540d\u548c\u5217\u540d<\/p>\n<p>#treeheight_row\u548ctreeheight_col\u53c2\u6570\u8bbe\u5b9a\u884c\u548c\u5217\u805a\u7c7b\u6811\u7684\u9ad8\u5ea6\uff0c\u9ed8\u8ba4\u4e3a50<\/p>\n<p>#display_numbers = TRUE\u53c2\u6570\u8bbe\u5b9a\u5728\u6bcf\u4e2a\u70ed\u56fe\u683c\u5b50\u4e2d\u663e\u793a\u76f8\u5e94\u7684\u6570\u503c<\/p>\n<p>#number_color\u53c2\u6570\u8bbe\u7f6e\u6570\u503c\u5b57\u4f53\u7684\u989c\u8272<\/p>\n<p># cellwidth\u548ccellheight\u53c2\u6570\u8bbe\u5b9a\u6bcf\u4e2a\u70ed\u56fe\u683c\u5b50\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0cmain\u53c2\u6570\u6dfb\u52a0\u4e3b\u6807\u9898<\/p>\n<p>\u4e86\u89e3\u540e\u6765\u7b80\u5355\u7ed8\u5236\u4e00\u4e2a\u5c1d\u8bd5\u4e00\u4e0b\uff1a<\/p>\n<p>pheatmap(test,scale = &#8220;row&#8221;,clustering_method = &#8220;average&#8221;,clustering_distance_rows = &#8220;correlation&#8221;,border=FALSE,treeheight_row = 50,treeheight_col =50,cellwidt = 15,cellheight = 20)<\/p>\n<p>\u8fd9\u91cc\u7528\u5230\u7684\u53c2\u6570\uff0c\u5982\u679c\u4f60\u4e0d\u660e\u767d\u610f\u4e49\u8bb0\u5f97\u53bb\u4e0a\u6587\u4e2d\u5bfb\u627e\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"599\" class=\"wp-image-23534\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-49-27.png?resize=640%2C599\" alt=\"\u622a\u5c4f2023-06-09 11.49.27\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-49-27.png?w=884 884w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-49-27.png?resize=300%2C281 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-49-27.png?resize=768%2C718 768w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-49-27.png?resize=600%2C561 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<h2>\u6dfb\u52a0\u884c\u4fe1\u606f\/\u5217\u4fe1\u606f\uff08\u7528\u4e8e\u4ee3\u8c22\u901a\u8def\u5206\u6790\u7b49\uff09<\/h2>\n<p>\u5728\u5206\u6790\u8fc7\u7a0b\u4e2d\u901a\u5e38\u4f1a\u5728\u884c\u6216\u8005\u5217\u6dfb\u52a0\u4e00\u884c\u5c5e\u4e8e<\/p>\n<p>#\u5148\u6784\u5efa\u4e00\u4e2a\u884c\u7684\u4fe1\u606f\uff08\u7528\u4e8e\u4e00\u4e9b\u4ee3\u8c22\u901a\u8def\u5bcc\u96c6\u5206\u6790\uff09<\/p>\n<p>annotation_row &lt;- data.frame(Path = factor(rep(c(&#8220;one&#8221;,&#8221;two&#8221;),5)))<\/p>\n<p>rownames(annotation_row) &lt;- paste(&#8220;Gene&#8221;,1:10,sep = &#8220;&#8221;)<\/p>\n<p># Path<\/p>\n<p>#Gene1 one<\/p>\n<p>#Gene2 two<\/p>\n<p>#Gene3 one<\/p>\n<p>#Gene4 two<\/p>\n<p>#Gene5 one<\/p>\n<p>#Gene6 two<\/p>\n<p>#Gene7 one<\/p>\n<p>#Gene8 two<\/p>\n<p>#Gene9 one<\/p>\n<p>#Gene10 two<\/p>\n<p>pheatmap(test, annotation_row = annotation_row)<\/p>\n<p>#\u521b\u5efa\u4e00\u4e2a\u884c\u7684\u8272\u5757<\/p>\n<p>ann_col = list(Path = c(one = &#8220;red&#8221;,two = &#8220;yellow&#8221;))<\/p>\n<p>#\u628a\u8272\u5757\u6620\u5c04\u5230\u56fe\u4e0a<\/p>\n<p>pheatmap(test, annotation_row = annotation_row, annotation_colors = ann_col)<\/p>\n<h2>\u5176\u5b83\u4e00\u4e9b\u64cd\u4f5c<\/h2>\n<p># gaps_row = c(3, 5)\u53c2\u6570\u5728\u7b2c3\u548c5\u884c\u5904\u6dfb\u52a0gap, \u8981\u6c42\u5bf9\u884c\u4e0d\u8fdb\u884c\u805a\u7c7b<\/p>\n<p>#cutree_col = 2\u53c2\u6570\u5c06\u5217\u6309\u805a\u7c7b\u6811\u7684\u7ed3\u679c\u5206\u6210\u4e24\u90e8\u5206, \u8981\u6c42\u5bf9\u5217\u8fdb\u884c\u805a\u7c7b<\/p>\n<p>#\u5bf9\u884c\u548c\u5217\u90fd\u4e0d\u805a\u7c7b\uff0c\u81ea\u5b9a\u4e49\u5212\u5206\u884c\u548c\u5217\u7684gap<\/p>\n<p>#labels_row \u53c2\u6570\u8bbe\u7f6e\u884c\u6807\u7b7e<\/p>\n<p>pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, cluster_cols = FALSE, gaps_row = c(3\uff0c6), gaps_col = c(2, 5)\uff0clabels_row = c())<\/p>\n<p>\u5728\u505a\u56fe\u7684\u8fc7\u7a0b\u4e2d\u6211\u4eec\u5e94\u8be5\u5145\u5206\u8003\u8651\u4f60\u60f3\u5c55\u793a\u7684\u5185\u5bb9\u662f\u4ec0\u4e48\uff0c\u8981\u4f20\u8fbe\u600e\u6837\u7684\u751f\u7269\u5b66\u5185\u5bb9\uff0c\u544a\u8bc9\u8bfb\u8005\u4f60\u7684\u7814\u7a76\u7ed3\u679c\uff0c\u800c\u4e0d\u662f\u4e00\u5473\u7684\u53ea\u8ffd\u6c42\u597d\u770b\u3002\u5728\u4f5c\u56fe\u7684\u8fc7\u7a0b\u4e2d\u4f60\u9700\u8981\u4ec0\u4e48\u5c31\u53bb\u641c\u7d22\u548c\u63a2\u7d22\u4ec0\u4e48\uff0c\u8fd9\u91cc\u53ea\u662f\u7b80\u5355\u7684\u70ed\u56fe\u7ed8\u5236\u65b9\u6cd5\uff0c\u4f46\u662f\u5177\u4f53\u600e\u6837\u5448\u73b0\u8fd8\u9700\u8981\u8fdb\u4e00\u6b65\u7684\u5b66\u4e60\u3002<\/p>\n<p>\u6b64\u5916\u8fd8\u53ef\u4ee5\u5bfb\u627e\u5f88\u591a\u5c0f\u5de5\u5177\u7ed8\u5236\u70ed\u56fe\u4f8b\u5982\uff1a<a href=\"http:\/\/www.biocloudservice.com\/747\/747.php\">http:\/\/www.biocloudservice.com\/747\/747.php<\/a><\/p>\n<p>\u4eca\u5929\u7684\u5206\u4eab\u5c31\u5230\u8fd9\u91cc\u53ed\uff0c\u5c0f\u4f19\u4f34\u4eec\u5982\u679c\u6709\u4ec0\u4e48\u95ee\u9898\u5c31\u548c\u5c0f\u679c\u8ba8\u8bba\u5427\uff5e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u70ed\u56fe\u5728\u4e2a\u7ec4\u5b66\u4e2d\u7684\u5e94\u7528\u5341\u5206\u7684\u5e7f\u6cdb\uff0c\u5728\u6587\u732e\u4e2d\u7ecf\u5e38\u51fa\u73b0\uff0c\u5229\u7528\u989c\u8272\u76f4\u63a5\u5c55\u793a\u5728\u4e0d\u540c\u6837\u672c\u4e2d\u5c55\u793a\u57fa\u56e0\u3001\u4ee3\u8c22\u7269\u3001\u7269\u79cd\u7b49\u8868\u8fbe\u7684\u6c34 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/23532"}],"collection":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23532"}],"version-history":[{"count":1,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/23532\/revisions"}],"predecessor-version":[{"id":23535,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/23532\/revisions\/23535"}],"wp:attachment":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23532"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}