{"id":1666,"date":"2025-08-23T21:24:26","date_gmt":"2025-08-23T13:24:26","guid":{"rendered":"https:\/\/cabit.top\/?p=1666"},"modified":"2025-08-23T21:33:34","modified_gmt":"2025-08-23T13:33:34","slug":"mothur_2_phyloseq-htmlunconstrained_ordinations","status":"publish","type":"post","link":"https:\/\/cabit.top\/?p=1666","title":{"rendered":"\u5fae\u751f\u7269\u7fa4\u843d\u591a\u6837\u6027\u5206\u6790\u6559\u7a0b\u4e0ePhyloseq"},"content":{"rendered":"\n<p>\u8fd9\u662f\u4e00\u4e2a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528Phyloseq\u5c06\u6269\u589e\u5b50\u5fae\u751f\u7269\u7ec4\u6570\u636e\u5bfc\u5165R\u5e76\u8fd0\u884c\u4e00\u4e9b\u57fa\u672c\u5206\u6790\u4ee5\u4e86\u89e3\u6837\u672c\u4e2d\u5fae\u751f\u7269\u7fa4\u843d\u591a\u6837\u6027\u548c\u7ec4\u6210\u7684\u6f14\u793a\u3002\u8be5\u8f6f\u4ef6\u5305\u7684\u66f4\u591a\u6f14\u793a\u53ef\u4ece\u4f5c\u8005\u5904\u83b7\u53d6\u3002\u6b64\u811a\u672c\u662f\u4f7f\u7528Rmarkdown\u521b\u5efa\u7684\u3002<\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aMichelle Berry<br>\u66f4\u65b0\u65e5\u671f\uff1a2016\u5e744\u670814\u65e5<\/p>\n\n\n\n<p>===================================================================<\/p>\n\n\n\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u662f\u5df2\u7ecf\u901a\u8fc7mothur\u6d41\u7a0b\u5904\u7406\u6210OTU\u548c\u5206\u7c7b\u8868\u7684illumina 16s\u6570\u636e\u3002\u5982\u679c\u60a8\u7684\u539f\u59cb\u5e8f\u5217\u6570\u636e\u662f\u901a\u8fc7\u4e0d\u540c\u7684\u6d41\u7a0b\u5904\u7406\u7684\uff0cPhyloseq\u6709\u591a\u79cd\u5bfc\u5165\u9009\u9879\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e9b\u6837\u672c\u662f\u57282014\u5e745\u6708\u81f311\u6708\u671f\u95f4\u4ece\u4f0a\u5229\u6e56\u897f\u90e8\u76c6\u5730\u7684\u4e09\u4e2a\u4e0d\u540c\u5730\u70b9\u6536\u96c6\u7684\u3002\u8be5\u6570\u636e\u96c6\u7684\u76ee\u6807\u662f\u4e86\u89e3\u4f0a\u5229\u6e56\u4e2d\u7684\u7ec6\u83cc\u7fa4\u843d\u5982\u4f55\u5728\u4e3b\u8981\u7531\u84dd\u85fb\u5c5eMicrocystis\u5f15\u8d77\u7684\u6709\u6bd2\u85fb\u7c7b\u6c34\u534e\u671f\u95f4\u53d1\u751f\u53d8\u5316\u3002<\/p>\n\n\n\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528Phyloseq\u8f6f\u4ef6\u5305\u5c06OTU\u8868\u548c\u6837\u672c\u5143\u6570\u636e\u5bfc\u5165R\u3002\u6211\u4eec\u5c06\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u63a2\u7d22\u6027\u5206\u6790\uff0c\u68c0\u67e5\u6837\u672c\u7684\u5206\u7c7b\u7ec4\u6210\uff0c\u5e76\u4f7f\u7528\u6392\u5e8f\u65b9\u6cd5\u5728\u4f4e\u7ef4\u7a7a\u95f4\u4e2d\u53ef\u89c6\u5316\u6837\u672c\u4e4b\u95f4\u7684\u5dee\u5f02\u6027\u3002\u6700\u540e\uff0c\u6211\u4eec\u5c06\u4f30\u8ba1\u6837\u672c\u7684\u03b1\u591a\u6837\u6027\uff08\u4e30\u5bcc\u5ea6\u548c\u5747\u5300\u5ea6\uff09\u3002<\/p>\n\n\n\n<p><strong>\u5e93<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code><em>#Load libraries<\/em>\n<strong>library<\/strong>(ggplot2)\n<strong>library<\/strong>(vegan)\n<strong>library<\/strong>(dplyr)\n<strong>library<\/strong>(scales)\n<strong>library<\/strong>(grid)\n<strong>library<\/strong>(reshape2)\n<strong>library<\/strong>(phyloseq)\n\n# Set working directory\nsetwd(\"~\/chabs\/miseq_may2015\/analysis\/\")\n\n# Source code files\n# miseqR.R can be found in this repository\nsource(\"~\/git_repos\/MicrobeMiseq\/R\/miseqR.R\")\n\n# Set plotting theme\ntheme_set(theme_bw())\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<\/blockquote>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><br>\u6570\u636e\u5bfc\u5165<\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5c06\u5bfc\u5165mothur\u5171\u4eab\u6587\u4ef6\u3001\u5171\u8bc6\u5206\u7c7b\u6587\u4ef6\u4ee5\u53ca\u6211\u4eec\u7684\u6837\u672c\u5143\u6570\u636e\uff0c\u5e76\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u4e00\u4e2aphyloseq\u5bf9\u8c61\u4e2d\u3002\u901a\u8fc7\u5c06\u6240\u6709\u6570\u636e\u7ed3\u6784\u5b58\u50a8\u5728\u4e00\u4e2a\u5bf9\u8c61\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u5404\u4e2a\u7ed3\u6784\u4e4b\u95f4\u8fdb\u884c\u4ea4\u4e92\u3002\u4f8b\u5982\uff0c\u6b63\u5982\u6211\u4eec\u7a0d\u540e\u4f1a\u770b\u5230\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6837\u672c\u5143\u6570\u636e\u4e2d\u7684\u6807\u51c6\u4eceOTU\u8868\u4e2d\u9009\u62e9\u67d0\u4e9b\u6837\u672c\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code><em># Assign variables for imported data<\/em>\nsharedfile = \"mothur\/chabs.shared\"\ntaxfile = \"mothur\/chabs-silva.taxonomy\"\nmapfile = \"other\/habs_metadata_cleaned.csv\"\n\n<em># Import mothur data<\/em>\nmothur_data &lt;- import_mothur(mothur_shared_file = sharedfile,\n  mothur_constaxonomy_file = taxfile)\n\n<em># Import sample metadata<\/em>\nmap &lt;- read.csv(mapfile)<\/code><\/pre>\n<\/blockquote>\n\n\n\n<p>\u6837\u672c\u5143\u6570\u636e\u53ea\u662f\u4e00\u4e2a\u5305\u542b\u6837\u672c\u5c5e\u6027\u5217\u7684\u57fa\u672ccsv\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6837\u672c\u5143\u6570\u636e\u7684\u9884\u89c8\u3002\u6b63\u5982\u60a8\u6240\u770b\u5230\u7684\uff0c\u6709\u4e00\u4e2a\u540d\u4e3aSampleID\u7684\u5217\uff0c\u5176\u4e2d\u5305\u542b\u6bcf\u4e2a\u6837\u672c\u7684\u540d\u79f0\u3002\u5176\u4f59\u5217\u5305\u542b\u4e0e\u6bcf\u4e2a\u6837\u672c\u76f8\u5173\u7684\u73af\u5883\u6216\u91c7\u6837\u6761\u4ef6\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>head(map)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">##    SampleID Date    Station     Shore Fraction   Type Samplenum Date_year<br>## 1 E0010_CNA 6\/16 nearshore2 nearshore      CNA sample     E0010   6\/16\/14<br>## 2 E0012_CNA 6\/16 nearshore1 nearshore      CNA sample     E0012   6\/16\/14<br>## 3 E0014_CNA 6\/16   offshore  offshore      CNA sample     E0014   6\/16\/14<br>## 4 E0016_CNA 6\/30 nearshore2 nearshore      CNA sample     E0016   6\/30\/14<br>## 5 E0018_CNA 6\/30 nearshore1 nearshore      CNA sample     E0018   6\/30\/14<br>## 6 E0020_CNA 6\/30   offshore  offshore      CNA sample     E0020   6\/30\/14<br>##   Month Days    pH SpCond StationDepth Secchi Temp Turbidity ParMC DissMC<br>## 1  June   20 8.080  290.6          5.1    0.9 22.4     10.10     0     NA<br>## 2  June   20 8.390  300.4          6.1    0.9 23.3     11.90     0     NA<br>## 3  June   20 8.308  281.7          8.5    4.0 22.5      1.34     0     NA<br>## 4  June   34 8.647  291.5          4.9    1.3 24.7      4.81     0     NA<br>## 5  June   34 8.435  290.0          6.0    1.4 24.5      4.01     0     NA<br>## 6  June   34 8.609  311.8          8.0    2.0 24.8      1.79     0     NA<br>##   Phycocyanin  Chla     DOC  SRP   TP  TDP  POC  PON    PP  N.P Nitrate<br>## 1        0.31 10.72 3.26025 4.16 36.1 12.3 0.68 0.15 23.84 6.15   482.5<br>## 2        1.06 34.37 3.40300 1.11 56.8 10.5 1.72 0.32 46.22 6.89   545.0<br>## 3        0.44 12.26 3.24075 0.24 19.7  4.4 0.84 0.13 15.31 8.31   475.0<br>## 4        1.69 19.94 3.84425 0.65 26.3  6.7 0.96 0.15 19.69 7.63   472.0<br>## 5        0.63  7.88 3.02160 0.17 19.4  4.6 0.59 0.12 14.83 7.92   444.5<br>## 6        1.59 12.93 3.38725 0.27 23.7  5.7 0.78 0.13 18.05 7.24   611.5<br>##   Ammonia     H2O2     CDOM<br>## 1    3.51 217.1213 4.212388<br>## 2    2.14 180.3269 4.252438<br>## 3   10.41 224.5438 3.523810<br>## 4    8.64 190.3620 3.454660<br>## 5   16.18 167.6386 4.595779<br>## 6   20.65 199.2388 6.792312<\/pre>\n\n\n\n<p>\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u6784\u9020\u51fd\u6570\u5c06\u8fd9\u4e2a\u6570\u636e\u6846\u8f6c\u6362\u4e3aphyloseq\u683c\u5f0f\u3002\u5c06\u6837\u672c\u6570\u636e\u5408\u5e76\u5230phyloseq\u5bf9\u8c61\u4e2d\u6240\u9700\u7684\u552f\u4e00\u683c\u5f0f\u8981\u6c42\u662f\uff0c\u884c\u540d\u5fc5\u987b\u4e0e\u60a8\u5171\u4eab\u6587\u4ef6\u548c\u5206\u7c7b\u6587\u4ef6\u4e2d\u7684\u6837\u672c\u540d\u79f0\u76f8\u5339\u914d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>map &lt;- sample_data(map)\n\n# Assign rownames to be Sample ID's\nrownames(map) &lt;- map$SampleID<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u9700\u8981\u5c06\u5143\u6570\u636e\u5408\u5e76\u5230\u6211\u4eec\u7684phyloseq\u5bf9\u8c61\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Merge mothurdata object with sample metadata\nmoth_merge &lt;- merge_phyloseq(mothur_data, map)\nmoth_merge\n\n## phyloseq-class experiment-level object\n## otu_table()   OTU Table:         &#91; 19656 taxa and 56 samples ]\n## sample_data() Sample Data:       &#91; 56 samples by 32 sample variables ]\n## tax_table()   Taxonomy Table:    &#91; 19656 taxa by 6 taxonomic ranks ]\n\n\u73b0\u5728\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3amoth.merge\u7684phyloseq\u5bf9\u8c61\u3002\u5982\u679c\u9700\u8981\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5c06\u7cfb\u7edf\u53d1\u80b2\u6811\u6216\u5305\u542bOTU\u4ee3\u8868\u6027\u5e8f\u5217\u7684fasta\u6587\u4ef6\u6dfb\u52a0\u5230\u8fd9\u4e2a\u5bf9\u8c61\u4e2d\u3002\u5728\u4efb\u4f55\u65f6\u5019\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u6253\u5370\u51faphyloseq\u5bf9\u8c61\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4ee5\u4fbf\u5feb\u901f\u67e5\u770b\u5176\u5185\u5bb9\u3002\n\n\u5728\u7ee7\u7eed\u8fdb\u884c\u5206\u6790\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u91cd\u65b0\u683c\u5f0f\u5316\u548c\u8fc7\u6ee4\u3002\n\n\u6211\u4eec\u7684\u5206\u7c7b\u6587\u4ef6\u7684\u5217\u540d\u662f\u4ec0\u4e48\uff1f<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>colnames(tax_table(moth_merge))\n\n## &#91;1] \"Rank1\" \"Rank2\" \"Rank3\" \"Rank4\" \"Rank5\" \"Rank6\"\n\n\u8fd9\u4e9b\u5206\u7c7b\u540d\u79f0\u6ca1\u6709\u5e2e\u52a9\uff0c\u6240\u4ee5\u8ba9\u6211\u4eec\u91cd\u547d\u540d\u5b83\u4eec\n\ncolnames(tax_table(moth_merge)) &lt;- c(\"Kingdom\", \"Phylum\", \"Class\", \n  \"Order\", \"Family\", \"Genus\")\n\n\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u8fc7\u6ee4\u6389\u6211\u4eec\u4e0d\u60f3\u5305\u542b\u5728\u5206\u6790\u4e2d\u7684\u6837\u672c\uff0c\u4f8b\u5982\u63d0\u53d6\u548c PCR \u7a7a\u767d\uff08\u6211\u4eec\u53ef\u4ee5\u7a0d\u540e\u67e5\u770b\u8fd9\u4e9b\u6837\u672c\uff0c\u770b\u770b\u90a3\u91cc\u6709\u4ec0\u4e48\uff09\n\n\u6ce8\u610f\uff1a\u6211\u7684\u5143\u6570\u636e\u4e2d\u6709\u4e00\u4e2a\u540d\u4e3a\u201cType\u201d\u7684\u5217prune_taxa\u547d\u4ee4\u4e2d\u51fa\u73b0\u7684\u201c.\u201d\u7528\u4e8e\u5f15\u7528\u6211\u4eec\u6b63\u5728\u7ba1\u9053\u4e2d\u7684\u6570\u636e\u5bf9\u8c61\uff08\u5220\u9664\u4e86\u975e\u6837\u672c\u7684 phyloseq \u5bf9\u8c61\uff09\n\nmoth_sub &lt;- moth_merge %>%\n  subset_samples(Type == \"sample\") %>%\n  prune_taxa(taxa_sums(.) > 0, .)\n\n\u73b0\u5728\u6211\u4eec\u5c06\u8fc7\u6ee4\u6389\u771f\u6838\u751f\u7269\u3001\u53e4\u7ec6\u83cc\u3001\u53f6\u7eff\u4f53\u548c\u7ebf\u7c92\u4f53\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u662f\u4e3a\u4e86\u6269\u589e\u7ec6\u83cc\u5e8f\u5217\u3002\u60a8\u53ef\u80fd\u5df2\u7ecf\u5728 mothur \u4e2d\u5b8c\u6210\u4e86\u6b64\u8fc7\u6ee4\uff0c\u4f46\u6700\u597d\u68c0\u67e5\u5206\u7c7b\u8868\u4e2d\u6ca1\u6709\u4efb\u4f55\u6f5c\u4f0f\u5185\u5bb9\u3002\u6211\u559c\u6b22\u5728\u8fd0\u884c mothur \u65f6\u5c06\u8fd9\u4e9b\u751f\u7269\u4fdd\u7559\u5728\u6211\u7684\u6570\u636e\u96c6\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4eec\u5f88\u5bb9\u6613\u4f7f\u7528 Phyloseq \u5220\u9664\uff0c\u6709\u65f6\u6211\u6709\u5174\u8da3\u63a2\u7d22\u5b83\u4eec\u3002<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>erie &lt;- moth_sub %>%\n  subset_taxa(\n    Kingdom == \"Bacteria\" &amp;\n    Family  != \"mitochondria\" &amp;\n    Class   != \"Chloroplast\"\n  )\n\nerie\n\n## phyloseq-class experiment-level object\n## otu_table()   OTU Table:         &#91; 7522 taxa and 56 samples ]\n## sample_data() Sample Data:       &#91; 56 samples by 32 sample variables ]\n## tax_table()   Taxonomy Table:    &#91; 7522 taxa by 6 taxonomic ranks ]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\u6458\u8981<\/h3>\n\n\n\n<p>\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u5206\u6790\uff0c\u6211\u4eec\u5c06\u67e5\u770b\u6837\u672c\u4e2d\u8bfb\u53d6\u8ba1\u6570\u7684\u5206\u5e03<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Make a data frame with a column for the read counts of each sample\nsample_sum_df &lt;- data.frame(sum = sample_sums(erie))\n\n# Histogram of sample read counts\nggplot(sample_sum_df, aes(x = sum)) + \n  geom_histogram(color = \"black\", fill = \"indianred\", binwidth = 2500) +\n  ggtitle(\"Distribution of sample sequencing depth\") + \n  xlab(\"Read counts\") +\n  theme(axis.title.y = element_blank())<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-12-1024x731.png\" alt=\"\" class=\"wp-image-1670\" srcset=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-12-1024x731.png 1024w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-12-300x214.png 300w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-12-768x549.png 768w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-12-670x479.png 670w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-12.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># mean, max and min of sample read counts\nsmin &lt;- min(sample_sums(erie))\nsmean &lt;- mean(sample_sums(erie))\nsmax &lt;- max(sample_sums(erie))\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5806\u53e0\u6761\u5f62\u56fe<\/h3>\n\n\n\n<p>\u8ba9\u6211\u4eec\u5236\u4f5c\u4e00\u4e2a Phyla \u7684\u5806\u53e0\u6761\u5f62\u56fe\uff0c\u4ee5\u4e86\u89e3\u8fd9\u4e9b\u6837\u672c\u4e2d\u7684\u7fa4\u843d\u6784\u6210\u3002<br><br>\u7531\u4e8e\u8fd9\u4e0d\u662f\u5b9a\u91cf\u5206\u6790\uff0c\u5e76\u4e14\u7531\u4e8e\u6211\u4eec\u5728\u8fd9\u4e2a\u6570\u636e\u96c6\u4e2d\u7684\u95e8\u591a\u4e8e\u6211\u4eec\u5408\u7406\u533a\u5206\u989c\u8272\u7684\u80fd\u529b\uff0843\uff01\uff09\uff0c\u6211\u4eec\u5c06\u4fee\u526a\u6389\u4f4e\u4e30\u5ea6\u7684\u7c7b\u7fa4\uff0c\u53ea\u5305\u62ec\u8d21\u732e\u8d85\u8fc7\u6bcf\u4e2a\u6837\u672c\u76f8\u5bf9\u4e30\u5ea6 2% \u7684\u95e8\u3002\u6839\u636e\u60a8\u7684\u6570\u636e\u96c6\u548c\u60a8\u6240\u63cf\u8ff0\u7684\u5206\u7c7b\u7ea7\u522b\uff0c\u60a8\u53ef\u4ee5\u8c03\u6574\u6b64\u4fee\u526a\u53c2\u6570\u3002\u5728\u4ee5\u540e\u7684\u5206\u6790\u4e2d\uff0c\u6211\u4eec\u5f53\u7136\u4f1a\u5305\u62ec\u8fd9\u4e9b\u7c7b\u7fa4\uff0c\u4f46\u73b0\u5728\u5b83\u4eec\u53ea\u4f1a\u5f04\u4e71\u6211\u4eec\u7684\u56fe\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># melt to long format (for ggploting) \n# prune out phyla below 2% in each sample\n\nerie_phylum &lt;- erie %>%\n  tax_glom(taxrank = \"Phylum\") %>%                     # agglomerate at phylum level\n  transform_sample_counts(function(x) {x\/sum(x)} ) %>% # Transform to rel. abundance\n  psmelt() %>%                                         # Melt to long format\n  filter(Abundance > 0.02) %>%                         # Filter out low abundance taxa\n  arrange(Phylum)                                      # Sort data frame alphabetically by phylum<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Set colors for plotting\nphylum_colors &lt;- c(\n  \"#CBD588\", \"#5F7FC7\", \"orange\",\"#DA5724\", \"#508578\", \"#CD9BCD\",\n   \"#AD6F3B\", \"#673770\",\"#D14285\", \"#652926\", \"#C84248\", \n  \"#8569D5\", \"#5E738F\",\"#D1A33D\", \"#8A7C64\", \"#599861\"\n)\n\n\n# Plot \nggplot(erie_phylum, aes(x = Date, y = Abundance, fill = Phylum)) + \n  facet_grid(Station~.) +\n  geom_bar(stat = \"identity\") +\n  scale_fill_manual(values = phylum_colors) +\n  scale_x_discrete(\n    breaks = c(\"7\/8\", \"8\/4\", \"9\/2\", \"10\/6\"),\n    labels = c(\"Jul\", \"Aug\", \"Sep\", \"Oct\"), \n    drop = FALSE\n  ) +\n  # Remove x axis title\n  theme(axis.title.x = element_blank()) + \n  #\n  guides(fill = guide_legend(reverse = TRUE, keywidth = 1, keyheight = 1)) +\n  ylab(\"Relative Abundance (Phyla > 2%) \\n\") +\n  ggtitle(\"Phylum Composition of Lake Erie \\n Bacterial Communities by Sampling Site\") <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-13-1024x731.png\" alt=\"\" class=\"wp-image-1672\" srcset=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-13-1024x731.png 1024w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-13-300x214.png 300w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-13-768x549.png 768w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-13-670x479.png 670w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-13.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8be5\u56fe\u662f\u4f7f\u7528<a href=\"http:\/\/www.cookbook-r.com\/Graphs\/Facets_(ggplot2)\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u523b\u9762<\/a>\u521b\u5efa\u7684\uff0c\u4ee5\u901a\u8fc7\u91c7\u6837\u7ad9\u6cbf y \u8f74\u5206\u79bb\u6837\u54c1\u3002\u8fd9\u662f ggplot \u7684\u4e00\u5927\u7279\u8272\u3002<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u6bcf\u4e2a\u6837\u672c\u7684\u603b\u548c\u5e76\u4e0d\u5b8c\u5168\u7b49\u4e8e 1\u3002\u8fd9\u53cd\u6620\u4e86\u88ab\u79fb\u9664\u7684\u7a00\u6709\u95e8\u3002\u5982\u679c\u60a8\u5e0c\u671b\u60a8\u7684\u7ed8\u56fe\u770b\u8d77\u6765\u50cf\u6240\u6709\u4e1c\u897f\u52a0\u8d77\u6765\uff0c\u60a8\u53ef\u4ee5\u5c06 position = \u201cfill\u201d \u6dfb\u52a0\u5230 geom_bar\uff08\uff09 \u547d\u4ee4\u4e2d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0d\u53d7\u7ea6\u675f\u7684\u6392\u5e8f<\/h3>\n\n\n\n<p>\u6269\u589e\u5b50\u6570\u636e\u7684\u6700\u4f73\u63a2\u7d22\u6027\u5206\u6790\u4e4b\u4e00\u662f\u65e0\u7ea6\u675f\u987a\u5e8f\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u67e5\u770b\u6211\u4eec\u6574\u4e2a\u793e\u533a\u6837\u672c\u7684\u6309\u7acb\u3002\u6211\u4eec\u5c06\u4f7f\u7528 miseqR.R \u4e2d\u7684 scale_reads\uff08\uff09 \u51fd\u6570\u6765\u7f29\u653e\u5230\u6700\u5c0f\u7684\u5e93\u5927\u5c0f\uff0c\u8fd9\u662f\u9ed8\u8ba4\u7684\u3002\u5982\u679c\u8981\u7f29\u653e\u5230\u53e6\u4e00\u4e2a\u6df1\u5ea6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u201cn\u201d\u53c2\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Scale reads to even depth \nerie_scale &lt;- erie %>%\n  scale_reads(round = \"round\") \n\n# Fix month levels in sample_data\nsample_data(erie_scale)$Month &lt;- factor(\n  sample_data(erie_scale)$Month, \n  levels = c(\"June\", \"July\", \"August\", \"September\", \"October\")\n)\n\n\n# Ordinate\nerie_pcoa &lt;- ordinate(\n  physeq = erie_scale, \n  method = \"PCoA\", \n  distance = \"bray\"\n)\n\n# Plot \nplot_ordination(\n  physeq = erie_scale,\n  ordination = erie_pcoa,\n  color = \"Month\",\n  shape = \"Station\",\n  title = \"PCoA of Lake Erie bacterial Communities\"\n) + \n  scale_color_manual(values = c(\"#a65628\", \"red\", \"#ffae19\",\n    \"#4daf4a\", \"#1919ff\", \"darkorchid3\", \"magenta\")\n  ) +\n  geom_point(aes(color = Month), alpha = 0.7, size = 4) +\n  geom_point(colour = \"grey90\", size = 1.5) <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-14-1024x731.png\" alt=\"\" class=\"wp-image-1674\" srcset=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-14-1024x731.png 1024w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-14-300x214.png 300w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-14-768x549.png 768w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-14-670x479.png 670w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-14.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8ba9\u6211\u4eec\u5c1d\u8bd5\u4e00\u4e0b NMDS\u3002\u5bf9\u4e8e NMDS \u56fe\uff0c\u8bbe\u7f6e\u79cd\u5b50\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a\u6837\u672c\u5728 alogrithm \u4e2d\u7684\u8d77\u59cb\u4f4d\u7f6e\u662f\u968f\u673a\u7684\u3002<\/p>\n\n\n\n<p>\u91cd\u8981\u63d0\u793a\uff1a\u5982\u679c\u60a8\u201c\u5185\u8054\u201d\u8ba1\u7b97\u60a8\u7684 bray-curtis \u8ddd\u79bb\u6307\u6807\uff0c\u5b83\u5c06\u6267\u884c\u5e73\u65b9\u6839\u53d8\u6362\u548c\u5a01\u65af\u5eb7\u661f\u5dde\u53cc\u6807\u51c6\u5316\u3002\u5982\u679c\u60a8\u4e0d\u60f3\u8981\u8fd9\u4e2a\uff0c\u60a8\u53ef\u4ee5\u5355\u72ec\u8ba1\u7b97\u60a8\u7684 bray-curtis \u8ddd\u79bb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set.seed(1)\n\n# Ordinate\nerie_nmds &lt;- ordinate(\n  physeq = erie_scale, \n  method = \"NMDS\", \n  distance = \"bray\"\n)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## Square root transformation\n## Wisconsin double standardization\n## Run 0 stress 0.1579025 \n## Run 1 stress 0.1819437 \n## Run 2 stress 0.240828 \n## Run 3 stress 0.1866267 \n## Run 4 stress 0.185961 \n## Run 5 stress 0.2000213 \n## Run 6 stress 0.1710585 \n## Run 7 stress 0.1711768 \n## Run 8 stress 0.2248862 \n## Run 9 stress 0.1580173 \n## ... procrustes: rmse 0.005865558  max resid 0.02795903 \n## Run 10 stress 0.1579805 \n## ... procrustes: rmse 0.00415466  max resid 0.02854737 \n## Run 11 stress 0.210445 \n## Run 12 stress 0.1579419 \n## ... procrustes: rmse 0.002487412  max resid 0.01392694 \n## Run 13 stress 0.1579215 \n## ... procrustes: rmse 0.004302403  max resid 0.02680986 \n## Run 14 stress 0.2153886 \n## Run 15 stress 0.2408162 \n## Run 16 stress 0.2032362 \n## Run 17 stress 0.1710288 \n## Run 18 stress 0.214908 \n## Run 19 stress 0.1819041 \n## Run 20 stress 0.1711611<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Plot \nplot_ordination(\n  physeq = erie_scale,\n  ordination = erie_nmds,\n  color = \"Month\",\n  shape = \"Station\",\n  title = \"NMDS of Lake Erie bacterial Communities\"\n) + \n  scale_color_manual(values = c(\"#a65628\", \"red\", \"#ffae19\",\n    \"#4daf4a\", \"#1919ff\", \"darkorchid3\", \"magenta\")\n  ) +\n  geom_point(aes(color = Month), alpha = 0.7, size = 4) +\n  geom_point(colour = \"grey90\", size = 1.5) <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-15-1024x731.png\" alt=\"\" class=\"wp-image-1675\" srcset=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-15-1024x731.png 1024w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-15-300x214.png 300w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-15-768x549.png 768w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-15-670x479.png 670w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-15.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>NMDS \u56fe\u8bd5\u56fe\u5728\u4e8c\u7ef4\u4e0a\u5c3d\u53ef\u80fd\u51c6\u786e\u5730\u663e\u793a\u6837\u672c\u4e4b\u95f4\u7684<strong>\u5e8f<\/strong>\u6570\u8ddd\u79bb\u3002\u62a5\u544a\u8fd9\u4e9b\u56fe\u7684\u5e94\u529b\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a\u9ad8\u5e94\u529b\u503c\u610f\u5473\u7740\u7b97\u6cd5\u5f88\u96be\u5728 2 \u7ef4\u4e0a\u8868\u793a\u6837\u672c\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u8be5\u56fe\u7684\u5e94\u529b\u8fd8\u53ef\u4ee5 &#8211; \u5b83\u662f .148\uff08\u901a\u5e38\u4efb\u4f55\u4f4e\u4e8e .2 \u7684\u503c\u90fd\u88ab\u8ba4\u4e3a\u662f\u53ef\u4ee5\u63a5\u53d7\u7684\uff09\u3002\u7136\u800c\uff0c\u8be5\u6570\u636e\u7684 PCoA \u80fd\u591f\u5728\u4e24\u4e2a\u7ef4\u5ea6\u4e0a\u663e\u793a\u5f88\u591a\u53d8\u5316\uff0c\u5e76\u4e14\u5b83\u66f4\u597d\u5730\u663e\u793a\u4e86\u8be5\u6570\u636e\u96c6\u4e2d\u7684\u65f6\u95f4\u8d8b\u52bf\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u575a\u6301\u4f7f\u7528\u8be5\u56fe\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PERMANOVA<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u5728\u7d20\u98df\u4e3b\u4e49\u8005\u4e2d\u4f7f\u7528 adonis \u51fd\u6570\u8fd0\u884c permanova \u6d4b\u8bd5\u7684\u793a\u4f8b\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6b63\u5728\u68c0\u9a8c\u4ee5\u4e0b\u5047\u8bbe\uff1a\u6211\u4eec\u4ece\u4e2d\u6536\u96c6\u6837\u672c\u7684\u4e09\u4e2a\u7ad9\u70b9\u5177\u6709\u4e0d\u540c\u7684\u8d28\u5fc3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set.seed(1)\n\n# Calculate bray curtis distance matrix\nerie_bray &lt;- phyloseq::distance(erie_scale, method = \"bray\")\n\n# make a data frame from the sample_data\nsampledf &lt;- data.frame(sample_data(erie))\n\n# Adonis test\nadonis(erie_bray ~ Station, data = sampledf)\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## \n## Call:\n## adonis(formula = erie_bray ~ Station, data = sampledf) \n## \n## Permutation: free\n## Number of permutations: 999\n## \n## Terms added sequentially (first to last)\n## \n##           Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)   \n## Station    2    0.6754 0.33772  2.7916 0.09531  0.003 **\n## Residuals 53    6.4118 0.12098         0.90469          \n## Total     55    7.0872                 1.00000          \n## ---\n## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Homogeneity of dispersion test\nbeta &lt;- betadisper(erie_bray, sampledf$Station)\npermutest(beta)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## \n## Permutation test for homogeneity of multivariate dispersions\n## Permutation: free\n## Number of permutations: 999\n## \n## Response: Distances\n##           Df   Sum Sq  Mean Sq      F N.Perm Pr(>F)\n## Groups     2 0.025388 0.012694 2.3781    999  0.114\n## Residuals 53 0.282915 0.005338<\/code><\/pre>\n\n\n\n<p>\u8be5\u8f93\u51fa\u544a\u8bc9\u6211\u4eec\uff0c\u6211\u4eec\u7684 adonis \u68c0\u9a8c\u5f88\u91cd\u8981\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u62d2\u7edd\u6211\u4eec\u7684\u4e09\u4e2a\u7ad9\u70b9\u5177\u6709\u76f8\u540c\u8d28\u5fc3\u7684\u539f\u5047\u8bbe\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0c\u6211\u4eec\u7684 betadisper \u7ed3\u679c\u5e76\u4e0d\u663e\u7740\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u80fd\u62d2\u7edd\u6211\u4eec\u7684\u7ec4\u5177\u6709\u76f8\u540c\u79bb\u6563\u5ea6\u7684\u539f\u5047\u8bbe\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u66f4\u6709\u4fe1\u5fc3\u6211\u4eec\u7684 adonis \u7ed3\u679c\u662f\u771f\u5b9e\u7684\u7ed3\u679c\uff0c\u800c\u4e0d\u662f\u7531\u4e8e\u7fa4\u4f53\u79bb\u6563\u5ea6\u7684\u5dee\u5f02<\/p>\n\n\n\n<p>\u8fd9\u91cc\u53ef\u4ee5\u505a\u66f4\u591a\u7684\u5206\u6790\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Bray-curtis \u4ee5\u5916\u7684\u8ddd\u79bb\u6307\u6807\uff0c\u6211\u4eec\u53ef\u4ee5\u6d4b\u8bd5\u4e0d\u540c\u7684\u5206\u7ec4\u53d8\u91cf\uff0c\u6216\u8005\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6d4b\u8bd5\u7ec4\u5408\u591a\u4e2a\u53d8\u91cf\u7684\u6a21\u578b\u6765\u521b\u5efa\u66f4\u590d\u6742\u7684 permanova\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u76ee\u524d\u8fd8\u6ca1\u6709\u9488\u5bf9 adonis \u5f00\u53d1\u7684<a href=\"https:\/\/stat.ethz.ch\/pipermail\/r-sig-ecology\/2012-November\/003364.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u4e8b\u540e\u6d4b\u8bd5<\/a>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u53d7\u7ea6\u675f\u7684\u6392\u5e8f<\/h3>\n\n\n\n<p>\u4e0a\u9762\u6211\u4eec\u4f7f\u7528\u65e0\u7ea6\u675f\u987a\u5e8f\uff08PCoA\u3001NMDS\uff09\u6765\u663e\u793a\u4f4e\u7ef4\u6837\u672c\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7ea6\u675f\u987a\u5e8f\u6765\u4e86\u89e3\u73af\u5883\u53d8\u91cf\u5982\u4f55\u4e0e\u7fa4\u843d\u6784\u6210\u7684\u8fd9\u4e9b\u53d8\u5316\u76f8\u5173\u8054\u3002\u6211\u4eec\u5c06\u987a\u5e8f\u8f74\u9650\u5236\u4e3a\u73af\u5883\u53d8\u91cf\u7684\u7ebf\u6027\u7ec4\u5408\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u73af\u5883\u5206\u6570\u7ed8\u5236\u5230\u4efb\u547d\u4e0a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Remove data points with missing metadata\n# \u5220\u9664\u7f3a\u5c11\u5143\u6570\u636e\u7684\u6570\u636e\u70b9\n\nerie_not_na &lt;- erie_scale %>%\n  subset_samples(\n    !is.na(Phycocyanin) &amp; \n      !is.na(SRP) &amp;\n      !is.na(pH) &amp; \n      !is.na(ParMC) &amp; \n      !is.na(H2O2)\n  )\n    \nbray_not_na &lt;- phyloseq::distance(physeq = erie_not_na, method = \"bray\")\n\n                            \n# CAP ordinate\ncap_ord &lt;- ordinate(\n    physeq = erie_not_na, \n    method = \"CAP\",\n    distance = bray_not_na,\n    formula = ~ ParMC + Nitrate + SRP + Phycocyanin + Ammonia + pH + H2O2\n)\n\n# CAP plot\ncap_plot &lt;- plot_ordination(\n  physeq = erie_not_na, \n  ordination = cap_ord, \n    color = \"Month\", \n    axes = c(1,2)\n) + \n    aes(shape = Station) + \n    geom_point(aes(colour = Month), alpha = 0.4, size = 4) + \n    geom_point(colour = \"grey90\", size = 1.5) + \n    scale_color_manual(values = c(\"#a65628\", \"red\", \"#ffae19\", \"#4daf4a\", \n        \"#1919ff\", \"darkorchid3\", \"magenta\")\n    )\n\n\n# Now add the environmental variables as arrows\narrowmat &lt;- vegan::scores(cap_ord, display = \"bp\")\n\n# Add labels, make a data.frame\narrowdf &lt;- data.frame(labels = rownames(arrowmat), arrowmat)\n\n# Define the arrow aesthetic mapping\narrow_map &lt;- aes(xend = CAP1, \n    yend = CAP2, \n    x = 0, \n    y = 0, \n    shape = NULL, \n    color = NULL, \n    label = labels)\n\nlabel_map &lt;- aes(x = 1.3 * CAP1, \n    y = 1.3 * CAP2, \n    shape = NULL, \n    color = NULL, \n    label = labels)\n\narrowhead = arrow(length = unit(0.02, \"npc\"))\n\n# Make a new graphic\ncap_plot + \n  geom_segment(\n    mapping = arrow_map, \n    size = .5, \n    data = arrowdf, \n    color = \"gray\", \n    arrow = arrowhead\n  ) + \n  geom_text(\n    mapping = label_map, \n    size = 4,  \n    data = arrowdf, \n    show.legend = FALSE\n  )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-16-1024x731.png\" alt=\"\" class=\"wp-image-1677\" srcset=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-16-1024x731.png 1024w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-16-300x214.png 300w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-16-768x549.png 768w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-16-670x479.png 670w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-16.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5728\u987a\u5e8f\u4e2d\u4f7f\u7528\u7684\u7ea6\u675f\u8f74\u4e0a\u8fdb\u884c\u6392\u5217\u65b9\u5dee\u5206\u6790<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>anova(cap_ord)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## Permutation test for capscale under reduced model\n## Permutation: free\n## Number of permutations: 999\n## \n## Model: capscale(formula = distance ~ ParMC + Nitrate + SRP + Phycocyanin + Ammonia + pH + H2O2, data = data)\n##          Df SumOfSqs      F Pr(>F)    \n## Model     7   3.1215 5.6409  0.001 ***\n## Residual 45   3.5574                  \n## ---\n## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u963f\u5c14\u6cd5\u591a\u6837\u6027<\/h3>\n\n\n\n<p>\u65e0\u8bba\u4f60\u505a\u4ec0\u4e48\uff0c\u4f30\u8ba1\u5fae\u751f\u7269\u7fa4\u843d\u7684 alpha \u591a\u6837\u6027\u90fd\u662f<a href=\"http:\/\/www.ncbi.nlm.nih.gov\/pmc\/articles\/PMC93182\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u6709\u95ee\u9898<\/a>\u7684\u3002\u6211\u6700\u597d\u7684\u5c1d\u8bd5\u662f\u5bf9\u6587\u5e93\u8fdb\u884c\u5b50\u91c7\u6837\uff0c\u4ee5\u66ff\u6362\u6765\u4f30\u8ba1\u771f\u5b9e\u79cd\u7fa4\u7684\u7269\u79cd\u4e30\u5ea6\uff0c\u540c\u65f6\u6807\u51c6\u5316\u62bd\u6837\u5de5\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>min_lib &lt;- min(sample_sums(erie))<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u5c06\u5b50\u91c7\u6837\u5230 1.563110^{4}\uff0c\u5373\u6700\u5c0f\u8bfb\u53d6\u6b21\u6570\u3002\u6211\u4eec\u5c06\u91cd\u590d\u6b64\u4f5c 100 \u6b21\uff0c\u5e76\u5bf9\u6bcf\u6b21\u8bd5\u9a8c\u7684\u591a\u6837\u6027\u4f30\u8ba1\u503c\u8fdb\u884c\u5e73\u5747\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Initialize matrices to store richness and evenness estimates\nnsamp = nsamples(erie)\ntrials = 100\n\nrichness &lt;- matrix(nrow = nsamp, ncol = trials)\nrow.names(richness) &lt;- sample_names(erie)\n\nevenness &lt;- matrix(nrow = nsamp, ncol = trials)\nrow.names(evenness) &lt;- sample_names(erie)\n\n# It is always important to set a seed when you subsample so your result is replicable \nset.seed(3)\n\nfor (i in 1:100) {\n  # Subsample\n  r &lt;- rarefy_even_depth(erie, sample.size = min_lib, verbose = FALSE, replace = TRUE)\n  \n  # Calculate richness\n  rich &lt;- as.numeric(as.matrix(estimate_richness(r, measures = \"Observed\")))\n  richness&#91; ,i] &lt;- rich\n  \n  # Calculate evenness\n  even &lt;- as.numeric(as.matrix(estimate_richness(r, measures = \"InvSimpson\")))\n  evenness&#91; ,i] &lt;- even\n}<\/code><\/pre>\n\n\n\n<p>\u8ba9\u6211\u4eec\u8ba1\u7b97\u89c2\u5bdf\u5230\u7684\u4e30\u5bcc\u5ea6\u548c\u9006\u8f9b\u666e\u68ee\u6307\u6570\u7684\u6bcf\u4e2a\u6837\u672c\u7684\u5e73\u5747\u503c\u548c\u6807\u51c6\u5dee\uff0c\u5e76\u5c06\u8fd9\u4e9b\u503c\u5b58\u50a8\u5728\u6570\u636e\u5e27\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create a new dataframe to hold the means and standard deviations of richness estimates\nSampleID &lt;- row.names(richness)\nmean &lt;- apply(richness, 1, mean)\nsd &lt;- apply(richness, 1, sd)\nmeasure &lt;- rep(\"Richness\", nsamp)\nrich_stats &lt;- data.frame(SampleID, mean, sd, measure)\n\n# Create a new dataframe to hold the means and standard deviations of evenness estimates\nSampleID &lt;- row.names(evenness)\nmean &lt;- apply(evenness, 1, mean)\nsd &lt;- apply(evenness, 1, sd)\nmeasure &lt;- rep(\"Inverse Simpson\", nsamp)\neven_stats &lt;- data.frame(SampleID, mean, sd, measure)<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u5bf9\u4e30\u5bcc\u5ea6\u548c\u5747\u5300\u5ea6\u7684\u4f30\u8ba1\u503c\u5408\u5e76\u5230\u4e00\u4e2a\u6570\u636e\u6846\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alpha &lt;- rbind(rich_stats, even_stats)<\/code><\/pre>\n\n\n\n<p>\u8ba9\u6211\u4eec\u4f7f\u7528 merge\uff08\uff09 \u547d\u4ee4\u5c06\u793a\u4f8b\u5143\u6570\u636e\u6dfb\u52a0\u5230\u6b64\u6570\u636e\u6846\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>s &lt;- data.frame(sample_data(erie))\nalphadiv &lt;- merge(alpha, s, by = \"SampleID\") <\/code><\/pre>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5c06\u5728\u7ed8\u5236\u4e4b\u524d\u5bf9\u8be5\u6570\u636e\u96c6\u4e2d\u7684\u4e00\u4e9b\u56e0\u7d20\u8fdb\u884c\u91cd\u65b0\u6392\u5e8f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alphadiv &lt;- order_dates(alphadiv)<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u5206\u9762\u7ed8\u5236\u65f6\u95f4\u5e8f\u5217\u4e2d\u7684\u4e24\u4e2a alpha \u591a\u6837\u6027\u5ea6\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggplot(alphadiv, aes(x = Date, y = mean, color = Station, group = Station, shape = Station)) +\n  geom_point(size = 2) + \n  geom_line(size = 0.8) +\n  facet_wrap(~measure, ncol = 1, scales = \"free\") +\n  scale_color_manual(values = c(\"#E96446\", \"#302F3D\", \"#87CEFA\")) +\n  scale_x_discrete(\n    breaks = c(\"7\/8\", \"8\/4\", \"9\/2\", \"10\/6\"),\n    labels = c(\"Jul\", \"Aug\", \"Sep\", \"Oct\"), \n    drop = FALSE\n  ) +\n  theme(\n    axis.title.x = element_blank(),\n    axis.title.y = element_blank()\n  )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-17-1024x731.png\" alt=\"\" class=\"wp-image-1678\" srcset=\"https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-17-1024x731.png 1024w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-17-300x214.png 300w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-17-768x549.png 768w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-17-670x479.png 670w, https:\/\/cabit.top\/wp-content\/uploads\/2025\/08\/image-17.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f1a\u8bdd\u4fe1\u606f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sessionInfo()<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>## R version 3.2.2 (2015-08-14)\n## Platform: x86_64-apple-darwin13.4.0 (64-bit)\n## Running under: OS X 10.9.5 (Mavericks)\n## \n## locale:\n## &#91;1] en_US.UTF-8\/en_US.UTF-8\/en_US.UTF-8\/C\/en_US.UTF-8\/en_US.UTF-8\n## \n## attached base packages:\n## &#91;1] grid      stats     graphics  grDevices utils     datasets  methods  \n## &#91;8] base     \n## \n## other attached packages:\n## &#91;1] phyloseq_1.12.2 reshape2_1.4.1  scales_0.4.0    dplyr_0.4.3    \n## &#91;5] vegan_2.3-1     lattice_0.20-33 permute_0.8-4   ggplot2_2.1.0  \n## \n## loaded via a namespace (and not attached):\n##  &#91;1] Biobase_2.28.0            splines_3.2.2            \n##  &#91;3] foreach_1.4.3             Formula_1.2-1            \n##  &#91;5] assertthat_0.1            stats4_3.2.2             \n##  &#91;7] latticeExtra_0.6-26       yaml_2.1.13              \n##  &#91;9] RSQLite_1.0.0             chron_2.3-47             \n## &#91;11] digest_0.6.9              GenomicRanges_1.20.8     \n## &#91;13] RColorBrewer_1.1-2        XVector_0.8.0            \n## &#91;15] colorspace_1.2-6          htmltools_0.2.6          \n## &#91;17] Matrix_1.2-2              plyr_1.8.3               \n## &#91;19] DESeq2_1.8.2              XML_3.98-1.3             \n## &#91;21] genefilter_1.50.0         zlibbioc_1.14.0          \n## &#91;23] xtable_1.7-4              BiocParallel_1.2.22      \n## &#91;25] annotate_1.46.1           mgcv_1.8-7               \n## &#91;27] IRanges_2.2.9             lazyeval_0.1.10          \n## &#91;29] nnet_7.3-11               BiocGenerics_0.14.0      \n## &#91;31] proto_0.3-10              survival_2.38-3          \n## &#91;33] RJSONIO_1.3-0             magrittr_1.5             \n## &#91;35] evaluate_0.8              nlme_3.1-122             \n## &#91;37] MASS_7.3-44               RcppArmadillo_0.6.100.0.0\n## &#91;39] foreign_0.8-66            tools_3.2.2              \n## &#91;41] data.table_1.9.6          formatR_1.2.1            \n## &#91;43] stringr_1.0.0             S4Vectors_0.6.6          \n## &#91;45] locfit_1.5-9.1            munsell_0.4.3            \n## &#91;47] cluster_2.0.3             AnnotationDbi_1.30.1     \n## &#91;49] lambda.r_1.1.7            Biostrings_2.36.4        \n## &#91;51] ade4_1.7-2                GenomeInfoDb_1.4.3       \n## &#91;53] futile.logger_1.4.1       iterators_1.0.8          \n## &#91;55] biom_0.3.12               igraph_1.0.1             \n## &#91;57] labeling_0.3              rmarkdown_0.9.5          \n## &#91;59] multtest_2.24.0           gtable_0.2.0             \n## &#91;61] codetools_0.2-14          DBI_0.3.1                \n## &#91;63] R6_2.1.1                  gridExtra_2.0.0          \n## &#91;65] knitr_1.11                Hmisc_3.17-0             \n## &#91;67] futile.options_1.0.0      ape_3.3                  \n## &#91;69] stringi_1.0-1             parallel_3.2.2           \n## &#91;71] Rcpp_0.12.3               geneplotter_1.46.0       \n## &#91;73] rpart_4.1-10              acepack_1.3-3.3<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u4e00\u4e2a\u5173\u4e8e\u5982\u4f55\u4f7f\u7528Phylos&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1666","post","type-post","status-publish","format-standard","hentry","category-softapp"],"_links":{"self":[{"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts\/1666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1666"}],"version-history":[{"count":8,"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts\/1666\/revisions"}],"predecessor-version":[{"id":1680,"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts\/1666\/revisions\/1680"}],"wp:attachment":[{"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}