{"id":666,"date":"2024-06-25T21:59:49","date_gmt":"2024-06-25T13:59:49","guid":{"rendered":"https:\/\/linguopeng.top\/?p=666"},"modified":"2024-06-25T22:24:30","modified_gmt":"2024-06-25T14:24:30","slug":"%e7%be%a4%e8%90%bd%e5%be%ae%e7%94%9f%e7%89%a9%e4%b8%8e%e7%8e%af%e5%a2%83%e5%9b%a0%e5%ad%90%e7%9b%b8%e5%85%b3%e6%80%a7rda%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=666","title":{"rendered":"\u8ddf\u7740iMeta\u5b66\u505a\u56fe | ggplot2\u7ed8\u5236\u4e3b\u5750\u6807\u5206\u6790PCoA\u56fe"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\u672c\u6559\u7a0b\u76f8\u5173\u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u81f3 https:\/\/github.com\/iMetaScience\/iMetaPlot\/tree\/main\/221129PCoA \u5982\u679c\u4f60\u4f7f\u7528\u672c\u4ee3\u7801\uff0c\u8bf7\u5f15\u7528\uff1a Yangquanwei Zhong. 2022. Differential microbial assembly processes and co-occurrence networks in the soil-root continuum along an environmental gradient. iMeta 1: e18. https:\/\/onlinelibrary.wiley.com\/doi\/full\/10.1002\/imt2.18\n\n\u4ee3\u7801\u7f16\u5199\u53ca\u6ce8\u91ca\uff1a\u519c\u5fc3\u751f\u4fe1\u5de5\u4f5c\u5ba4\n\n# \u52a0\u8f7d\u5305\nlibrary(phyloseq)\nlibrary(vegan)\nlibrary(ape)\nlibrary(ggplot2)\n\nset.seed(42) # \u56fa\u5b9a\u968f\u673a\u79cd\u5b50\n#\u968f\u673a\u751f\u62101000\u4e2aotu\u4e4b\u95f4\u7684\u8fdb\u5316\u6811\ntree &lt;- rtree(1000, rooted = T, tip.label = paste(\"s\",1:1000, sep=\"\"))\n#\u968f\u673a\u751f\u6210OTU\u8868 10\u4e2a\u6837\u54c1\u54041000\u4e2aotu\notu &lt;- matrix(sample(0:10, 10000, replace = T), nrow = 10)\n\n#\u7ed9\u6bcf\u4e2aotu\u547d\u540d\uff0c\u548c\u8fdb\u5316\u6811\u8282\u70b9\u540d\u79f0\u4fdd\u6301\u4e00\u81f4\ncolnames(otu) &lt;- tree$tip.label\ndf &lt;- phyloseq(otu_table(otu, taxa_are_rows = F), phy_tree(tree)) # \u751f\u6210phyloseq\u5bf9\u8c61\n#\u8ba1\u7b97\u975e\u52a0\u6743\u7684uniFrac\u8ddd\u79bb\u77e9\u9635\uff0c\u8861\u91cf10\u4e2a\u6837\u54c1\u4e4b\u95f4\u7684\u7fa4\u843d\u8c31\u7cfb\u5dee\u5f02\ndist.mat &lt;- phyloseq::UniFrac(df, weighted=F)\n# \u7528\u975e\u52a0\u6743\u7684uniFrac\u8ddd\u79bb\u77e9\u9635\u505apcoa\u5206\u6790\ndf.pcoa &lt;- pcoa(dist.mat)\n\n# \u63d0\u53d6pcoa\u7ed3\u679c\u8868\u683c\uff0c\u7528\u4e8e\u7ed8\u56fe\ndf.plot&lt;-data.frame(df.pcoa$vectors)\n\n#\u83b7\u5f97\u5750\u6807\u8f74\u4e0a\u663e\u793a\u7684\u767e\u5206\u6bd4\nx_label&lt;-round(df.pcoa$values$Rel_corr_eig&#91;1]*100, 2)\ny_label&lt;-round(df.pcoa$values$Rel_corr_eig&#91;2]*100, 2)\n#\u5bf9\u6570\u636e\u8fdb\u884c\u4eba\u4e3a\u5206\u7ec4\ndf.plot$group &lt;- ifelse(df.plot$Axis.1&lt;0,\"Agropyron cristatum\",\"Reaumuria Linn.\")\n\n#\u7528ggplot2\u753b\u56fe\uff0c\u7136\u540e\u6dfb\u52a0\u4e00\u4e2a\u8868\u793a\u5206\u7ec4\u7684\u692d\u5706\np &lt;- ggplot(data=df.plot,aes(x=Axis.1,y=Axis.2,color=group,shape=group))+geom_point(size=5)+theme_bw()+theme(panel.grid = element_blank())+geom_vline(xintercept = 0,lty=\"dashed\")+geom_hline(yintercept = 0,lty=\"dashed\")+labs(x=paste0(\"PCoA1\",x_label,\"%\"),y=paste0(\"PCoA2\",y_label,\"%\"))+stat_ellipse(data=df.plot,alpha=0.3)\nggsave('pcoa_plot.png', p)\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\/pcoa_plot.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1500\" height=\"899\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/pcoa_plot.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-674\"\/><\/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-666","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/666","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=666"}],"version-history":[{"count":4,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/666\/revisions"}],"predecessor-version":[{"id":676,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/666\/revisions\/676"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}