{"id":678,"date":"2024-06-25T22:37:55","date_gmt":"2024-06-25T14:37:55","guid":{"rendered":"https:\/\/linguopeng.top\/?p=678"},"modified":"2024-06-25T22:37:55","modified_gmt":"2024-06-25T14:37:55","slug":"%e8%b7%9f%e7%9d%80imeta%e5%ad%a6%e5%81%9a%e5%9b%be%ef%bd%9c%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%a7%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=678","title":{"rendered":"\u8ddf\u7740iMeta\u5b66\u505a\u56fe\uff5c\u7fa4\u843d\u5fae\u751f\u7269\u4e0e\u73af\u5883\u56e0\u5b50\u76f8\u5173\u6027\u5206\u6790"},"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\/221030RDA \u5982\u679c\u4f60\u4f7f\u7528\u672c\u4ee3\u7801\uff0c\u8bf7\u5f15\u7528\uff1a Zeyu Zhang. 2022. Tomato microbiome under long-term organic and conventional farming. iMeta 1: e48. https:\/\/onlinelibrary.wiley.com\/doi\/full\/10.1002\/imt2.48\n# \u4ee3\u7801\u7f16\u5199\u53ca\u6ce8\u91ca\uff1a\u519c\u5fc3\u751f\u4fe1\u5de5\u4f5c\u5ba4\n# R\u5305\u68c0\u6d4b\u548c\u5b89\u88c5\n# 1.\u5b89\u88c5\u6838\u5fc3R\u5305circlize\u4ee5\u53ca\u4e00\u4e9b\u529f\u80fd\u8f85\u52a9\u6027R\u5305\uff0c\u5e76\u8f7d\u5165\u6240\u6709R\u5305\u3002\n# \u68c0\u67e5\u5fae\u751f\u7269\u7fa4\u843d\u5206\u6790\u5305vegan\uff0c\u5982\u6ca1\u6709\u5219\u5b89\u88c5\nif (!require(\"vegan\"))\n  install.packages(\"vegan\")\n# \u68c0\u67e5ggplot2\u62d3\u5c55\u5305\u7528\u56fe\u4e2d\u6587\u5b57\u7684\u6807\u6ce8\nif (!require(\"ggrepel\"))\n  install.packages(\"ggrepel\")\n# \u52a0\u8f7d\u5305\nlibrary(vegan)\nlibrary(ggrepel)\n# \u751f\u6210\u6d4b\u8bd5\u6570\u636e\n# 2. \u8bbe\u5b9a\u968f\u673a\u79cd\u5b50\u5e76\u5f00\u59cb\u968f\u673a\u751f\u6210\u54cd\u5e94\u53d8\u91cf\u6570\u636e\uff0c\u5171\u751f\u621080\u6761\u6837\u672c\uff0c\u6570\u503c\u4e3a0-10\u4e4b\u95f4\u7684\u968f\u673a\u6570\nset.seed(42) #\u8bbe\u7f6e\u968f\u673a\u79cd\u5b50\ndata1 &lt;- data.frame(TN = runif(80, 0, 10), \n                    PH = runif(80, 0, 10), \n                    Organic=runif(80, 0, 10), \n                    AN=runif(80, 0, 10),\n                    Enterobacteriaceae=runif(80, 0, 10), \n                    Pseudomonas=runif(80, 0, 10),\n                    Caulobacteraceae=runif(80, 0, 10),\n                    Terribacillus=runif(80, 0, 10),\n                    Sphingobacteriunm=runif(80, 0, 10),\n                    Burkholderiaceae=runif(80, 0, 10),\n                    Micrococcales=runif(80, 0, 10),\n                    Chryseobacterium=runif(80, 0, 10),\n                    Cronobacter=runif(80, 0, 10),\n                    Bacillus=runif(80, 0, 10),\n                    Nanoarchaeaeota=runif(80, 0, 10),\n                    Flavobacterium=runif(80, 0, 10))\n# \u53ef\u9009\uff1a\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\n# write.table(data1, file=\"data1.txt\", sep=\"\\t\", quote = F, row.names = T, col.names = T)\n# data1 &lt;- read.table(\"data1.txt\")\ndata1  # \u67e5\u770bdata1\u6570\u636e\u6846\n# 3.\u5bf9\u54cd\u5e94\u53d8\u91cf\u8fdb\u884chellinger\u6807\u51c6\u5316\uff0c\ndata1 &lt;- decostand(data1, method = \"hellinger\")\n# 4.\u968f\u673a\u751f\u6210\u89e3\u91ca\u53d8\u91cf\u6570\u636e\uff0cdata2\u548cdata1\u884c\u6570\u5fc5\u987b\u76f8\u7b49\uff0c\u524d\u976240\u6761\u6570\u636e\u5c5e\u4e8eCON\u5904\u7406\uff0c\u540e\u976240\u6761\u6570\u636e\u5c5e\u4e8eORG\u5904\u7406\ndata2 = data.frame(group = c(rep(\"CON1\",10),rep(\"CON2\",10), rep(\"CON3\",10), rep(\"CON4\",10), rep(\"ORG1\",10),rep(\"ORG2\",10), rep(\"ORG3\",10), rep(\"ORG4\",10)))\n# \u53ef\u9009\uff1a\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\n# write.table(data2, file=\"data2.txt\", sep=\"\\t\", quote = F, row.names = T, col.names = T)\n# data2 &lt;- read.table(\"data2.txt\")\n# RDA\u5206\u6790\u548c\u6392\u5e8f\u56fe\u7ed8\u5236\n# 5.RDA\u5206\u6790\u672c\u8eab\u5b9e\u73b0\u5f88\u7b80\u5355\uff0c\u4e00\u884c\u4ee3\u7801\u5373\u53ef\nres &lt;- rda(data1 ~ . , data2)\n# 6.\u4e0b\u9762\u8fdb\u884c\u4e00\u4e9b\u753b\u56fe\u524d\u7684\u6570\u636e\u5904\u7406\uff0c\u6ce8\u610f\u8fd9\u91cc\u4f7f\u7528factor\u51fd\u6570\u7684levels\u53c2\u6570\u53ea\u662f\u4e3a\u4e86\u6539\u53d8ggplot2\u4e2dlegend\u7684\u987a\u5e8f\u4ece\u800c\u548c\u539f\u56fe\u4fdd\u6301\u4e00\u81f4\uff0c\u9ed8\u8ba4\u5f3a\u51b5\u4e0b\u753b\u51fa\u7684\u56feORG\u5728CON\u4e0b\u65b9\ncentroids &lt;- as.data.frame(res$CCA$centroids&#91;,c(1,2)]) #\u53d6RDA1\uff0cRDA2\u8f74\u8fdb\u884c\u53ef\u89c6\u5316\ncentroids$group &lt;- factor(c(rep('CON',4),rep('ORG',4)), levels = c('ORG', 'CON')) # \u7ed9centroids\u6570\u636e\u6846\u589e\u52a0\u4e00\u5217\u7528\u4e8e\u533a\u5206\u5f62\u72b6\u5e76\u4e0a\u8272\nrda.v &lt;- as.data.frame(res$CCA$v&#91;,c(1,2)])\nrda.v$name = row.names(rda.v) #\u63d0\u53d6\u54cd\u5e94\u53d8\u91cf\u540d\u79f0\u7528\u4e8e\u5728\u56fe\u4e2d\u5c55\u793a\u6807\u7b7e\n# \u5236\u5b9a\u753b\u56fe\u4e2d\u7bad\u5934\u7684\u6570\u636e\uff0c\u5e76\u7ed9\u51fa\u989c\u8272\narrow_data &lt;- data.frame(x=rda.v&#91;,1], y = rda.v&#91;,2], x_end=0, y_end=0, name=rda.v&#91;,3], col='blue')\narrow_data&#91;arrow_data$name %in% c('PH', 'TN', 'Organic', 'AN'), ]$col &lt;- 'red'\n# 7.\u5f00\u59cb\u753b\u56fe\uff0c\u5148\u628a\u89e3\u91ca\u53d8\u91cf\u7684point\u753b\u51fa\np1 &lt;- ggplot(data = centroids) + \n  geom_point(size=2, aes(x = RDA1,y=RDA2,color=group, shape=group))\np1\n# 8. \u5728p1\u7684\u57fa\u7840\u4e0a\u518d\u628a\u54cd\u5e94\u53d8\u91cf\u7684\u4f4d\u7f6e\u6807\u51fa\uff0c\u6ce8\u610f\u6807\u7b7e\u659c\u4f53\np2 &lt;- p1 + ggrepel::geom_text_repel(data = arrow_data, aes(x,y,label=name), \n                                    size=3, fontface=\"italic\")\np2\n# 9. \u8fdb\u4e00\u6b65\u753b\u51fa\u54cd\u5e94\u53d8\u91cf\u7684\u7bad\u5934\np3 &lt;- p2 + geom_segment(data = arrow_data,\n                        aes(x=0, y=0, xend=x, yend=y), \n                        arrow = arrow(length = unit(0.05,\"inches\")), color = arrow_data$col, size=.8) \np3\n# 10. \u8fd9\u662f\u56fe\u5df2\u7ecf\u57fa\u672c\u6210\u578b\uff0c\u9700\u8981\u518d\u5b8c\u5584\u4e00\u4e9b\u7ec6\u8282\u3002\u753b\u51fa\u865a\u7ebf\np4 &lt;- p3 + geom_hline(yintercept = 0, linetype = \"dashed\", size=1.2) + \n  geom_vline(xintercept = 0,linetype = \"dashed\", size=1.2)\np4\n# 11. \u53bb\u6389\u56fe\u4f8b\u6807\u9898\u5e76\u6539\u53d8\u56fe\u4f8b\u4f4d\u7f6e\np5 &lt;- p4 + theme(legend.title = element_blank(), legend.position = c(0.9,0.8), legend.background = element_blank())\np5\n# 12. \u8ddd\u79bb\u6210\u529f\u53ea\u5dee\u4e00\u6b65\u5566\uff0c\u6539\u53d8\u80cc\u666f\u989c\u8272\uff0c\u5e76\u4fee\u6539\u6a2a\u7eb5\u5750\u6807\u8f74\np6 &lt;- p5 + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),\n                 panel.background = element_blank(), axis.line = element_line(colour = \"black\"), panel.border = element_rect(colour = \"black\", fill=NA, size=1)) + labs(x = 'RDA1(53.5%)',y = 'RDA2(24.11%)')\nggsave('RDA_plot.pdf', p6, height = 10, width = 8)  # \u4fdd\u5b58\u56fe\u7247\u5e76\u8bbe\u7f6e\u5bbd\u548c\u9ad8<\/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\/RDA_plot.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"576\" height=\"720\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2024\/06\/RDA_plot.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-680\"\/><\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\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-678","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/678","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=678"}],"version-history":[{"count":1,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/678\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/678\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}